Functionsprint() | displays information on the screen | input() | receives information from the user | int() | convert a value to an integer | float() | decimal number | str() | string(word) | print() | use print statement with parenthesis |
randomimport random
intlist =[1,2,3,4,5,6]
random_int = random.choice(intlist)
fplist =[1.22,2.33,3.44,4.55]
random_fp =random.choice(fplist)
strlist =["1" , "5" , "6" , "7"]
random_str =random.choice(strlist)
mylist =[2 ,2.33 ,"lily"]
random_item = random.choice(mylist)
|
circlewhile True:
pi = 3.1415
user_radius = input( " Insert radius here... " )
radius = float(user_radius)
area = pi radius*2
print ( " the area of the circle is",area)
print ( " Allahu Akbar")
|
defdef printDefinition(word):
if word =="function":
print (""" A function is the code""")
elif word == "variable":
print (""" A variable is thing that can change""")
else:
print (""" A return value is somethind the function give back""")
print ("""A argument value is something that pass the function""")
print (""" A parameter is something that pass the function""")
print (""" A string is the list of characteristic""")
printDefinitions()
|
| | additionstring+string | combine together | string+number | crash | number+number | math-addition |
Math+ | plus | / | divide | * | multiple | ** | power | % | remainder |
vocabularyvariable | hold a value and can be change | string | a list that have " " | integer | number | syntax | grammar | print | show information |
textname = "tim GIRARD" print (name.upper()) print (name.lower()) print (name.capitalize()) print (name.title()) | TIM GIRARD tim girard Tim girard Tim Girard |
loopshoppinglist = ['salmon', 'bacon', 'water', 'jelly', 'ham']
print (shoppinglist)
list_num = 0
while list_num < len(shoppinglist):
print ("List:",shoppinglist[list_num])
list_num = list_num + 1
for item in shoppinglist:
print (item)
numbers = range(120)
for num in numbers:
print (num)
|
true falseTrue or anything ==True
False and anything ==false
|
if statmentnum= int(input(" enter a number"))
if num<0:
print(num,"is negative")
elif num==0:
print (num,"is zero")
else:
print(num,"is possitive")
|
stop loopwhile True:
user_input=input("enter number:")
if user_input != "exit":
print(len(user_input))
else:
break
|
| | codewhile true:
user_radius = input(" what is the radius")
radius = float(user_radius)
pi = 3.1415
area = pi radius*2
print("the area of circle is", area)
|
code (copy)while true:
user_radius = input(" what is the radius")
radius = float(user_radius)
pi = 3.1415
area = pi radius*2
print("the area of circle is", area)
|
listimport random
intlist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
random_int = random.choice (intlist)
print(intlist,random_int)
fplist = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
random_fp = random.choice (fplist)
print (fplist,random_fp)
strlist = ["1","2","3","4","5","6","7","8","9"]
random_str = random.choice (strlist)
print (strlist,random_str)
mylist = ["adam","mild","loveadam","levine","3","4.6",424,674,5.733]
random_item = random.choice (mylist)
print (mylist,random_item)
myvar1 = 1
myvar2 = 2
myvar3 = 3
varlist = (myvar1,myvar2,myvar3)
random_var = random.choice (varlist)
print (varlist,random_var)
|
symbolif/elif/else
conditionals
While
loop
for
list all the thing
!=
If values of two operands are not equal, then condition becomes true.
==
test if the 2 value are the same
<
less than
<=
If the value of left operand is less than or equal to the value of right operand, then condition becomes true.
>
greater than
>=
If the value of left operand is greater than or equal to the value of right operand, then condition becomes true.
|
areadef areaOfCirclr (r):
area = 3.14r*2
return area
|
function1def computeThis (a1,b2):
return a1*b2
a1 = int(input("Enter a number"))
b2 = int(input("Enter a number"))
print (computeThis (a1,b2))
|
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment