1/9
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
Conditional
A conditional is a statement that runs different code depending on whether a condition is true or false. If, elif, and else are all used within conditionals to execute different blocks of code depending on whether conditions are true or false.
If statement
An if statement is a control structure that executes a block of code only if a condition is true.
Elif
Elif is used in a conditional to check another condition if the previous one was false.
Else
Else defines the block of code that runs if previous conditions in a conditional are false. Often, an else branch is used to raise an error for an invalid mode.
Loop
A loop is a control structure that repeats code multiple times. Loops are useful when you want to go through all items in a list, all characters in a string, values in a dictionary, or repeat something several times.
For loop
A for loop repeats once for each item in a an iterable object. For example, if you had the list numbers = [1, 2, 3] and then your code was
for number in numbers:
print (number)
you would get
1
2
3
While loop
A while loop keeps repeating as long as a condition is true. For example:
count = 0
while count < 3:
print(count)
count += 1The count starts as 0, the loop runs because 0 < 3, prints 0, then increases to 1. Prints 1 then increases to 2. Prints 2 then increases to 3. Stops because 3 < 3 is false.
Output
0
1
2Nested conditional
A nested conditional is a conditional statement placed inside another conditional statement.
Branch
A branch is one of the possible paths a program can take depending on a condition.