
Chapter 3 (branches, conditions and while loops)
Random
What is a module?
A module is a file that contains code that can be run in the program
import random
- This would import the random module
random.randint(1, 6)
- this generates a random number 1 to 6
random.randrange(6)
- This generates a random number 0 to 5, the 6 represents how many numbers
if statement
if condition:
code
- The condition must equate to being true to run
Define condition
A condition is a evaluation that equates to be true or false
Comparison operators
==
!=
≥=
>
≤=
- The else statement will run if the if statements condition evaluates to being false
- elif will only run if the prior condition evaluates to being false, if it evaluates to being true it will not run
What does a indentation represent
A block of code
'apples' > 'oranges' true or false
this is FALSE
0 or void elements true or false
FALSE
-5 true or false
TRUE
While loop
while condition:
code
What operator exits the loop
break
What is a sentry variable
It is the variable that is in the condition statement of the loop
What is a simple condition
This is where you compare two values
What is a compound condition
This is where you use logical operators in the condition
What is a logical operator
This is things like: and, not, or