0
while True:
n1 = float(input("Enter first number: "))
n2 = float(input("Enter second number: "))
tot = n1 + n2
print('total is',tot)
n3 = input('Try Again? Y/N ')
if n3.upper() == 'Y':
    continue
elif n3.upper() == 'N':
    print('Exiting...')
    break
else:
    print('Not a valid answer')

Hi all. I have 2 questions:

  1. How do I go back to ('Try Again? Y/N ') if the user did not press a valid answer?
  2. It crashes when the user does not enter a number for n1 and n2. How to solve that please?
Shredz
  • 15
  • 4

0 Answers0