WhiteTail WhiteTail - 24 days ago 6
Python Question

Restart Python program if user input to 'run again?' is 'y'

while True:
# main program

number = (" ")
total = 0

num1 = int(input("enter a number"))
total = total + num1
num2 = int(input("enter a number"))
total = total + num2
num3 = int(input("enter a number"))
total = total + num3

if total > 100:
print("That's a big number!")
else:
print("That's a small number.")
print(total)

while True:
answer = raw_input("Run again? (y/n): ")
if answer in y, n:
break
print("Invalid input.")
if answer == 'y':
continue
else:
print 'Goodbye'
break


Essentially I want the program to restart when the user enters 'y' as a response to 'run again?' Any help would be vastly appreciated. Thanks.

Answer

Your code looks really messed up. Try to write some better(clean) code next time.

while True:
    total = 0

    num1 = int(input("enter a number"))
    num2 = int(input("enter a number"))
    num3 = int(input("enter a number"))
    total = num1 + num2 + num3

    if total > 100:
        print("That's a big number!")
    else:
        print("That's a small number.")
    print(total)

    con = int(input("Run again? 1/0: "))
    if con==0:
        break