# 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 ๐ŸŒด๐Ÿ’ž#

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 ๐ŸŒ…#

sunset

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:

  1. Start with a countdown value of 10.

  2. Print the countdown value, then decrease it by 1 in each iteration.

  3. 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 ๐Ÿง #

memory

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:

  1. Use a while loop to let Lucy try up to 5 times.

  2. Print "Lucy remembers: Henry!" if she succeeds within the limit.

  3. Print "Lucy couldn't remember." if she exceeds 5 attempts.

Implementation Details:#

  1. Use the provided function memory game to simulate Lucyโ€™s memory game.

  2. Define a variable attempts to keep track of the number of attempts. Initialize it to 0.

  3. Inside the while loop, increment the attempts variable by 1 in each iteration.

  4. If attempts is equal to 3, print "Lucy remembers: Henry!" and break out of the loop.

  5. If attempts is less than 3, 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")