| Python
                        
                                                                                    
                                                                                            | string+string | combine together |  
                                                                                            | string+number | crash |  
                                                                                            | number+number | math-addition |  
                                                                                            | number-number | math-substarction |  
                                                                                            | number*number | math-mutiplication |  
                                                                                            | number/number | math-division |  
                                                                                            | ** | exponent |  
                                                                                            | % | modulo |  
                                                                                            | boolean | True/False |  
                                                                                            | # | single line comment |  
                                                                                            | """ | multi-line comment |  Reverse Word
                        
                                                                                    
                                                                                            | 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 ("Revears:", reverse) |  Letter
                        
                                    
                        | name = "tim GIRARD"print (name. upper())
 print (name. lower())
 print (name. capitalize())
 print (name. title())
 
 TIM GIRARD
 tim girard
 Tim girard
 Tim Girard
 |  For loop and list
                        
                                    
                        | shoppinglist = ['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)
 |  covert to int
                        
                                    
                        | user_word = input ("Please enter a number")number = int (user_word)
 print (number * 10)
 |  random
                        
                                    
                        | import random
 mylist = ['mild', 'stamp', 'nae', 'mint']
 print(mylist[0])
 counter = 0
 while counter < 10:
 random_item = random.choice(mylist)
 print (random_item)
 counter = counter + 1
 |  random game
                        
                                    
                        | import randommylist = ['mild','lily','stamp','nae', 'mint']
 chance=3
 score=0
 random_item = random.choice (mylist)
 
 while chance > 0 :
 print (mylist)
 guess = input ("Guess a word: ")
 
 if (guess in mylist):
 
 if (guess == random_item):
 print ("That's correct!")
 score= score+100
 print ("score",score)
 random_item = random.choice (mylist)
 else:
 print ("Sorry, wrong choice!")
 chance = chance-1
 print ("chance remaining:",chance)
 
 else:
 print ("No,not in the list")
 chance= chance-1
 print ("chance remaining",chance)
 
 if (chance<1):
 print ("Game over!the word was", random_item)
 print ("final score", score)
 |  |  | vocabulary
                        
                                                                                    
                                                                                            | str | string |  
                                                                                            | int | integer |  
                                                                                            | float | decimal number |  
                                                                                            | len | lengh |  
                                                                                            | syntax | a structure of the program |  
                                                                                            | print | An instruction that causes the Python interpreter to display a value on the screen. |  
                                                                                            | Variable | The name of something that the code has given a value to |  
                                                                                            | Single Equal (=) | assigns the value on the right to a variable on the left |  
                                                                                            | Double Equal (==) | Tests if two things have the same value |  
                                                                                            | input | to convert things you enter as if they were Python code |  Convert to binary
                        
                                                                                    
                                                                                            | user_number = " " |  
                                                                                            | user_number != "0" : |  
                                                                                            | user_number = input ("enter a number to convert to binary") |  
                                                                                            | number = int (user_number) |  
                                                                                            | binary_string = " " |  list
                        
                                    
                        | import randomintlist = [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)
 |  Math-circle
                        
                                    
                        | while 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")
 |  triangle
                        
                                    
                        | def areaoftriangle (base,height) :return baseheight0.5
 base = float (input('Enter the base of the triangle'))
 height = float (input ('Enter the height of the triangle'))
 print("The area of the triangle is",areaoftriangle(base,height))
 
 def volumeofprism (area,height):
 return areaoftriangle*height
 print ("The volume of the prism is",volumeofprism(area,height))
 |  if/ elif/ else
                        
                                    
                        | def printdefinition (word):
 if word == "function":
 print("""
 function lets you use code
 """)
 
 elif word== "string":
 print("""
 string is list of character
 """)
 else:
 print ("unknown word")
 user_word = input ("Enter a word to define: ")
 printdefinition(user_word)
 |  text+decoration
                        
                                    
                        | def myprint (text):print ("" + str(text) + "")
 return
 myprint (1)
 myprint ("hello")
 
 def myprint2 (text, decoration):
 print (decoration + str(text)+ decoration)
 return
 myprint2(123,"+++++++")
 myprint2 ("hello","----")
 
 myvar = "hello"
 def myvarprint (myvar):
 print (myvar)
 return
 myvarprint ("hi")
 print (myvar)
 |  |  | symbol
                        
                                                                                    
                                                                                            | if/else | conditional |  
                                                                                            | while | loop |  
                                                                                            | for | list all the things |  
                                                                                            | == | test if two values are the same |  
                                                                                            | < | less than |  
                                                                                            | > | more than |  
                                                                                            | <= | if the value of left operand is less than or equal to the value of right operand,then condition becomes true |  
                                                                                            | >= | if the value of left operand is greater than or equal to the value of right operand,then condition becomes true |  guess word game
                        
                                                                                    
                                                                                            | import random |  
                                                                                            | guesslist = ['grape', 'orange', 'apple'] |  
                                                                                            | 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') |  mild
                        
                                    
                        | word=""wordlist = [ ]
 letterofword = [ ]
 while True :
 while (word!="quit"):
 word=input ("Please enter a word")
 print (len(word))
 def palindrom(word):
 index =0
 check = True
 while index < len(word)
 if word
 |  circle
                        
                                    
                        | def doubleIt(number):return number*2
 print (doubleIt (3))
 print (doubleIt (2.5))
 print (doubleIt("hi"))
 
 
 myvar = doubleIt (doubleIt (3))
 print (myvar)
 
 
 def areaOfCircle (radius):
 if (radius<=0):
 return "Error: radius <=0"
 pi = 3.1415
 area = pi(radius*2)
 return area
 user_radius = input("Enter the radius: ")
 radius = float(user_radius)
 print ("The area of the circle is", areaOfCircle(radius))
 |  for loop
                        
                                    
                        | """list = [2,3,4,5,6,7]
 list_num = 0
 while (list_num < len(list)):
 print (list[list_num])
 list_num = list_num+1
 """
 forlist = [1,2,3,4]
 for item in forlist:
 print (item)
 |  test
                        
                                    
                        | theList = ["mild","mint","stamp"]for item in theList:
 print (item)
 
 whilelist = ["1","2","3"]
 list_num = 0
 while list_num<len(whilelist):
 print (whilelist[list_num])
 list_num = list_num+1
 
 """
 repeatedly accepts user input, print out the lenght. stop when user enter "exit"
 """
 
 while True:
 user_input = input ("Please enter a word")
 if user_input == "exit":
 break
 print (len(user_input))
 
 """
 function+no parameter repeatedly accepts user input until user enter "stop"
 """
 def theFunction():
 while True:
 user_input = input ("Please enter a number")
 if user_input =="stop":
 return
 theFunction()
 
 """
 takes two parameter a1,b2, function return the product of two parameter
 """
 def computeThis (a1,b2):
 return a1*b2
 a1 = int(input("Please enter a number"))
 b2 = int(input("Please enter a number"))
 print (computeThis (a1,b2))
 
 """
 has 1 argrument called string. string+decoration
 """
 def finalFunction (string):
 print ("*"+str(string)+ "*")
 string = input ("Please enter a word")
 print (finalFunction(string))
 |  | 
            
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment