|
input()
|
receive information from user
|
|
print()
|
show info that received from user
|
|
int()
|
change info to integer
|
|
float()
|
convert value into decimal number
|
|
>
|
more than
|
|
<
|
less than
|
|
>=
|
equal or more than
|
|
<=
|
equal or less than
|
firstname = input("What is your firstname? ")
lastname = input("What is you lastname? ")
fullname = firstname + " " + lastname
print (fullname)
letternum = int(input("What is the letternumber? "))
if len(fullname) >= int(letternum):
print (fullname[letternum])
letterprint = int(input("How many times to print the letter? "))
if int(letterprint) <= 100:
print (fullname[letternum] * int(letterprint))
else:
print ("Too many letters to print!")
else:
print ("Invalid letter number, try again")
|
==
|
equal to
|
|
!=
|
not equal to
|
|
+
|
add number
|
|
-
|
minus number
|
|
*
|
multiply number
|
|
%
|
find remainder between two number
|
|
/
|
divide number
|
|
**
|
power the number
|
|
Variable
|
info from user that can change
|
|
Syntax
|
the computer's grammar
|
word = input("Enter a word: ")
index = 0
reverse = ''
while index < len(word):
reverse = word[index] + reverse
index = index+1
print("Reverse: ",reverse)
user_radius = input("What is your radius ?")
radius = float(user_radius)
pi = 3.1415
area = (pi * (radius ** 2))
print ("The area of the circle is", area)
|
string
|
information user added
|
|
len()
|
number of string
|
|
boolean
|
true/false
|
import random
mylist = ['barbie', 'kitty', 'my melody', 'sailor moon', 'pretty cure']
random_item = random.choice(mylist)
print(random_item)
print(mylist[0])
print(mylist)
chance = 5
score = 0
while chance > 0:
user_guess = input("Guess a word ")
if user_guess == random_item:
score = score+100
print ("That's correct")
print ("score: ", score)
random_item = random.choice(mylist)
elif user_guess in mylist:
chance = chance-1
print ("Sorry, wrong choice!")
print ("chance remaining ", chance)
else:
chance = chance-1
print ("Sorry, that's not even on the list")
(chance == 0, print("game over"))
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.