Python
string + string |
combine together |
string + number |
crash |
number + number |
math-addition |
number-number |
math-subtraction |
number*number |
math-multiplication |
number/number |
math-division |
number**number |
math-exponent |
number%number |
finding a remainder |
bolean |
True/False |
# |
single-line comment |
"""" |
multi-line comment |
Countdown
while True:
user_number = input(" Enter ur number Here...")
number = int(user_number)
countdown_string = ""
while number > 0:
countdown_string = countdown_string + str(number)
number = number - 1
print (countdown_string) |
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) |
|
|
Vocabulary
str |
string |
int |
integer |
float |
decimal number |
syntax |
the structure of a program |
syntax error |
An error in a program that makes it impossible to parse |
len |
Return the length of an object |
Modulus(%) |
Show the remainder of the division |
Single Equal (=) |
assigns the value on the right to a variable on the left |
Double Equal (==) |
test if the 2 value are the same |
String |
a series of sentences that the user will use. Usually surrounded by double quotes |
Variable |
A thing that can be changed |
input |
convert things you enter |
List
import 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) |
List
import 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) |
|
|
Symbol
if/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. |
Guess word game
import random |
#create a list |
guesslist = ['adam', 'mild', 'levine'] |
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!") |
else: |
if user_input not in guesslist: |
print ("sorry, that's wrong") |
List
import 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) |
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") |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by mmildmilds