1/15
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
int
integer: number without a decimal
float
number with a decimal
str
string: text
input()
ask the user to type something in
input()
ask the user to type something in
Conditionals
If statement
else : stops asking questions and just runs, only used once if “if” statement is false
elif : Extra conditions, asks another question, can have multiple but stops once the previous ones are false
* For Else and Elif, you must exit the “If block” first
Comparison Operators: <,>, greater than or equal to, or less than or equal to
<, >, <=, >=, or ==
*= means an assignment, like print=
How to use a String
print(“Hello world”)
Make sure to use ““
Don’t need to write str
for loops
for item in collection
they repeat until the number of items in your collection.
EX. for name in [“Alice”, “bob”, “Charlie”]:
print(name)
Range()
this range starts at 0 and goes up to ,not including, the number inside the parens
Ex. For number in range(3):
print(number)
Outcome:
0
1
2
Range (#,#)
When you want to type down numbers in a certain range
you can do this two ways, one using just one number and adding an amount to the number using f””, or just giving the exact range with (x,x)
EX.
for num in range (7)
print(f”num +3”)
Output: 3,4,5,6,7,8,9
for num in range (3,9)
print(num)
Output: 3,4,5,6,7,8,9