Oct 04: While Loops and Random
Learning Objectives
After today's class, you should be able to:
- Identify the three main components of a
while
loop. - Use the
random
module to generate random numbers. - Explain when to use a
while
loop versus afor
loop.
Reminders¶
- Read Ch 7 – ideally:
- 1st half before Friday
- 2nd half before Monday
- Submit HW 7 – ideally:
- 1 and 2 before Friday
- 3 and 4 before Monday
POGIL Activity¶
- While Loops
- If you are absent today, complete this activity at home
- Bring your completed activity to class or office hours
Example Code¶
Model 1
i = 0
while i < 3:
print("the number is", i)
i = i + 1
print("goodbye")
Question 9
total_count.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Model 3
guess_number.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
coin_toss.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|