1/59
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
integer input
variable = int(input("Enter number: "))
float input
variable = float(input("Enter number: "))
output/display/print
print(variable)
print message
print("Message")
variable example
score = 0
name = "Ali"
height = 1.75
convert to string
str(value)
convert to integer
int(value)
convert to float
float(value)
addition
total = total + number
subtraction
score = score - 1
multiplication
answer = num1 * num2
division
average = total / amount
quotient/integer division
result = 10 // 3
modulus/remainder
result = 10 % 3
powers/exponents
result = 2 ** 3
concatenation/joining strings
fullName = firstName + " " + lastName
basic if statement
if condition:
print("True")
if else statement
if condition:
print("Yes")
else:
print("No")
if elif else statement
if condition1:
print("Option 1")
elif condition2:
print("Option 2")
else:
print("Other")
equal to comparison
==
not equal comparison
!=
greater than comparison
>
less than comparison
<
greater than or equal comparison
>=
less than or equal comparison
<=
logical and
if age >= 18 and age <= 65:
logical or
if answer == "Y" or answer == "y":
for loop fixed repetitions
for i in range(5):
print(i)
for loop through list
for item in items:
print(item)
while loop
while condition:
print("Running")
validation/password while loop
password = ""
while password != "computer":
password = input("Enter password: ")
total algorithm
total = 0
for i in range(amount):
number = int(input())
total = total + number
average algorithm
average = total / amount
counting algorithm
count = 0
if condition:
count = count + 1
largest value algorithm
largest = 0
if number > largest:
largest = number
smallest value algorithm
smallest = number
if number < smallest:
smallest = number
validation loop
age = int(input())
while age < 0 or age > 120:
age = int(input("Enter again: "))
string length
len(word)
string slicing
word[start:end]
string slicing example
word[0:3]
create list/array
names = ["Ali", "Bob", "Sam"]
access item in list
print(names[0])
append/add item to list
names.append("John")
linear search algorithm
found = False
for item in items:
if item == target:
found = True
if found:
print("Found")
else:
print("Not found")
function template
def functionName(parameter):
return value
function example
def triple(number):
return number * 3
procedure template
def procedureName(parameter):
print(parameter)
global variable
global score
open file for reading
file = open("file.txt", "r")
read one line from file
line = file.readline()
read entire file line by line
for line in file:
print(line.strip())
close file
file.close()
open file for writing
file = open("file.txt", "w")
write to file
file.write("Hello\n")
nested if statement
if condition1:
if condition2:
print("Yes")
nested loops
for i in range(3):
for j in range(3):
print(i, j)
import random module
import random
random integer
random.randint(1, 10)
boolean false
found = False
boolean true
found = True