|
int()
|
Change number to be number integer
|
|
float()
|
Change number to be decimal number
|
|
str()
|
A list of number, letter and symbols
|
|
print()
|
Show information that you want on the screen
|
|
len()
|
The length of the string
|
|
#
|
Comment, no effect
|
|
import random + random.choice
|
pick random item in the list
|
while True:
word = input("Please enter a word")
index = 0
reverse = ' '
while int(index) < len(word):
reverse = word[index] + (reverse)
index = int(index) + 1
print ("Reverse: ", reverse)
mystr = "Hello"
letter_num = 0
while letter_num < len(mystr):
print (mystr[letter_num])
letter_num = letter_num + 1
"""
Python Intro Assignment #2
name
student number
"""
#Ask the user for a radius of a circle
user_radius = input("What is a radius of a circle?")
#Convert the given radius to a floating point
radius = float(user_radius)
#Make a variable called pi
pi = float(3.1415)
#Calculate the area of the circle using exponents
area = pi(radius*2)
#Display the area of the circle to the user
print ("The area of the circle is", area)
|
string + string
|
Combine together
|
|
string + number
|
Crash
|
|
number + number
|
Math - addition
|
|
string * number
|
Combine that string
|
|
string * string
|
Crash
|
|
number * number
|
Math - multiply
|
|
string ** string
|
Crash
|
|
number ** number
|
Math - exponent
|
|
string ** number
|
Crash
|
user_number = ' '
while user_number != '0':
user_number = input("Enter a number to convert to binary")
number = int(user_number)
binary_string = ''
while (number > 0):
remainder = number%2
binary_string = str(remainder)+ binary_string
number = number//2
print ("Binary string is",binary_string)
name = "jirat PRASERTMAK"
print (name.upper()) -----------> JIRAT PRASERTMAK
print (name.lower()) -----------> jirat prasertmak
print (name.capitalize()) -----------> Jirat prasertmak
print (name.title()) -----------> Jirat Prasertmak
|
==
|
equal to
|
|
!=
|
no equal to
|
|
<
|
less than
|
|
>
|
more than
|
|
<=
|
less than or equal
|
|
>=
|
more than or equal
|
|
%
|
Modulo, find the remainder
|
|
variable
|
Hold a value and can be changed
|
|
syntax
|
Grammar or structure of language
|
|
modulo
|
Find the remainder
|
|
boolean
|
True or false
|
|
floating point
|
The number in decimal
|
user_number = input("What number do you want to count down? ")
number = int(user_name)
countdown-string = ''
while number > 0
countdown_number = countdown_string + str(number) + " "
number = number - 1
#print(number)
print (countdown_string)
import random
#Create a list
guesslist = ['vesicle', 'lysosome', 'chloroplast', 'ribosome', 'vacuole']
chance = 3
score = 0
print (guesslist)
while chance != 0:
random_item = random.choice(guesslist)
user_input = input("Please guess a word: ")
if user_input == random_item:
print ("That's correct!")
score = score + 100
print ("Score:", score)
else:
if user_input not in guesslist:
print ("Sorry, that isn't even in the list!")
chance = chance - 1
print ("Chance Remaining:", chance)
else:
print ("Sorry, wrong choice!")
chance = chance - 1
print ("Chance Remaining:", chance)
if chance == 0:
print ("The word was", random_item)
print ("The score is", score)
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.