week4_lecture2
week4_lecture2
Do
Something
False False
Refresher
Click Link:
3. Turtles and while
loops
Breakout Session 1
▪ Write code to print all the
numbers from 0 to 20 that aren’t
evenly divisible by either 3 or 5. Open your
▪ Zero is divisible by everything and
should not appear in the output. notebook
Click Link:
4. Breakout Session 1
Random Module
▪ This module implements pseudo-
random number generators for
various distributions. Open your
import random notebook
random.uniform()
Click Link:
random.random()
5. Random Module
random.randint()
…
Guessing Game
▪ Let’s build a simple guessing game.
▪ Get the computer to choose a
random integer from 0 to 100.
▪ Ask the user for a guess and allow the
user to input a guess or "q“.
▪ If the user inputs "q" print a nice
message and end the program.
▪ If the user enters a guess, tell them if
they should guess higher, lower, or if
they got it right.
▪ If they got it right, print a nice
message and quit.
Guessing Game
▪ Get the computer to choose a random integer
from 0 to 100.
▪ The computer selects 45.
45
0 100
Guessing Game
▪ The user guesses 64.
▪ The computer says LOWER.
Guess
45 64
0 100
Guessing Game
45
0 64
Guessing Game
▪ The user guesses 40.
▪ The computer says HIGHER.
Guess
40 45
0 64
Guessing Game
45
40 64
Guessing Game
▪ The user guesses 45.
▪ The computer says YOU WIN.
Guess
45
40 64
Guessing Game
▪ Let’s build a simple guessing game.
1. Get the computer to choose a
random integer from 0 to 100.
2. Ask the user for a guess and allow
Open your
the user to input a guess or "q“. notebook
3. If the user inputs "q" print a nice
message and end the program.
4. If the user enters a guess, tell them Click Link:
if they should guess higher, lower, 6. A Simple Guessing
or if they got it right.
Game
5. If they got it right, print a nice
message and quit.
Lecture Recap