Answer to Question #345294 in Python for jazz

Question #345294

Ask the use if they want a cup of tea. If they replay with “no” or “n” repeat the question. Once the loop stops display the message “Sorry,we have run out of tea”

1
Expert's answer
2022-05-27T09:39:42-0400
while True:
    try:
        answer=input('Would you like a cup of tea? ')
        if answer=='yes' or answer=='y':
            print ('Sorry,we have run out of tea.')
            break   
        if answer!='n' and answer!='no' and answer!='yes' and answer!='y':     
            raise Exception              
    except Exception:
        print ('Valid answers: yes, y, no, n.')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS