additon
string+string |
combine together |
string+number |
crash |
number+number |
math-addition |
functions
print() |
displays information on the screen |
intput() |
receives information from the user |
int() |
converts a value to an integer |
float() |
change the number into decimal |
len() |
count the string |
str() |
change the value into string |
codes
print (name.upper()) |
print (name.lower()) |
print (name.capitalize()) |
print (name.title()) |
|
|
vocabulary
varible |
holds a value and can be changed |
string |
a list of characters such as numbers, letters, symbols |
math symbols
== |
equal to |
!= |
not equal to |
+ |
plus |
- |
minus |
* |
times |
/ |
divide |
% |
remainder |
** |
power |
< |
lessthan |
> |
more than |
<= |
less than or equal to |
>= |
more than or equal to |
function loop-
def creatlist (quitword):
print('keep entering words to add to the list')
print('quit when word=', quitword)
mylist = []
while True:
user_word = input('enter a word to add to the list')
If user_qord == quitwords:
return my list
dulplicateword = False
for item in mylist
if item == user_word
duplicateword == true
if (duplicatedword == True):
print ('duplicate word!')
else:
mylist.append(user_word)
userlist = createlist("hello")
print(userlist)
|
|
|
Multiplication and Exponents
string * number |
combine that string multiple times |
string * string |
crash |
number * number |
math multiply |
string ** string |
crash |
number ** number |
math exponents |
string ** number |
crash |
python shop code
print ("welcone to our shop")
price=0
size=('s','m','l','xl')
colour=('red','black','white')
sock=('want','not want')
print (size)
shirt = (input('what shirt size do you want?'))
if shirt == ('s'):
price = price+70
print( "the price now is",price)
elif shirt ==('m'):
price = price+80
print( "the price now is",price)
elif shirt ==('l'):
price = price+90
print( "the price now is",price)
elif shirt ==('xl'):
price = price+100
print( "the price now is",price)
else:
print("our shop doesn't have this size.")
print (colour)
shirtcolour= (input('what colour of shirt do you want?'))
if shirtcolour == ('red'):
price = price+70
print( "the price now is",price)
elif shirtcolour ==('black'):
price = price+80
print( "the price now is",price)
elif shirtcolour ==('white'):
price = price+90
print( "the price now is",price)
else:
print("our shop don't have this colour")
print (size)
pant = (input('what pant size do you want?'))
if pant == ('s'):
price = price+70
print( "the price now is",price)
elif pant ==('m'):
price = price+80
print( "the price now is",price)
elif pant ==('l'):
price = price+90
print( "the price now is",price)
elif pant ==('xl'):
price = price+100
print( "the price now is",price)
else:
print("our shop doesn't have this size.choose again")
|
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment