QUESTION IMAGE
Question
often we need to double check that the user gave us the information we asked for. in previous labs we often shortcut this by saying if they didnt enter one, they must have entered the other (if they didnt type y, they must have typed n).
in this lab, we will ask for y or n and keep asking until the user enters one of them.
- fill in the function get_y_or_n()
a. ask the user have you had a good day? (y/n)
b. keep asking until the user answers y or n
c. return the y or n answer (this part is already set up for you)
- in the main part of the program (below where the get_y_or_n() is called), if the user answered y, say excellent. if the user answers n, tell them i hope your day gets better
Step1: Define the function with loop
def get_y_or_n():
while True:
user_input = input("Have you had a good day? (y/n)").lower()
if user_input in ['y', 'n']:
return user_input
Step2: Add main part
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
= get_y_or_n()
if answer == 'y':
print("Excellent")
else:
print("I hope your day gets better")