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”
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.')
Comments
Leave a comment