# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment
responses = initialize_assignment("10_while_loops_50_dates_q", "week_4", "readings", assignment_points = 26.0, assignment_tag = 'week4-readings')
# Initialize Otter
import otter
grader = otter.Notebook("10_while_loops_50_dates_q.ipynb")
โ ๐บ 50 First Dates ๐ด๐#
Relive the sweet and quirky moments of 50 First Dates while mastering Pythonโs while
loops!
# Run this block of code by pressing Shift + Enter to display the question
from questions._10_while_loops_50_dates_q import Question1
Question1().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._10_while_loops_50_dates_q import Question2
Question2().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._10_while_loops_50_dates_q import Question3
Question3().show()
Sunset Countdown ๐ #
Instructions:#
Henry and Lucy are watching the sunset together. Write a Python program that counts down from 10
to 1
before saying โGoodnight!โ Use a while
loop to:
Start with a countdown value of
10
.Print the countdown value, then decrease it by
1
in each iteration.Print
"Goodnight!"
after the loop ends.
Example Output:#
10
9
8
7
6
5
4
3
2
1
Goodnight!
def countdown():
...
countdown()
grader.check("FirstDate-SunsetCountdown")
Memory Game ๐ง #
Instructions:#
Lucy is trying to remember Henryโs name. She repeats the name "Henry"
until she gets it right, but she can only attempt up to 5
times. Write a Python program to simulate this:
Use a
while
loop to let Lucy try up to5
times.Print
"Lucy remembers: Henry!"
if she succeeds within the limit.Print
"Lucy couldn't remember."
if she exceeds5
attempts.
Implementation Details:#
Use the provided function memory game to simulate Lucyโs memory game.
Define a variable
attempts
to keep track of the number of attempts. Initialize it to0
.Inside the
while
loop, increment theattempts
variable by1
in each iteration.If
attempts
is equal to3
, print"Lucy remembers: Henry!"
andbreak
out of the loop.If
attempts
is less than3
, print"Lucy couldn't remember."
.
Example Output:#
Attempt 1: Lucy tries to remember...
Attempt 2: Lucy tries to remember...
Attempt 3: Lucy tries to remember...
Lucy remembers: Henry!
def memory_game():
...
grader.check("FirstDate-MemoryGame")
Submitting Assignment#
Please run the following block of code using shift + enter
to submit your assignment, you should see your score.
from pykubegrader.submit.submit_assignment import submit_assignment
submit_assignment("week4-readings", "10_while_loops_50_dates_q")