Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

often we need to double check that the user gave us the information we …

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.

  1. 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)

  1. 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

Explanation:

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

Answer:

= get_y_or_n()
if answer == 'y':
print("Excellent")
else:
print("I hope your day gets better")