0

This is a simple program to check if a number is odd or even.I want to check if the user wants to continue or not and when I run it I get an Invalid Syntax Error on the break line, what have I got wrong?

while True:
if cont != "no":
    num = (int(input("Type a number. ")))
    num_remainder = num % 2
    if num_remainder == 0:
        print ()
        print (num, " is an even number.")
    else:
        print ()
        print (num, " is an odd number.")
cont= (input("Would you like to continue?")
    continue
else:
    break

Thanks

1
  • 2
    Your identation is wrong (at least for attached code) Commented Jan 16, 2016 at 21:47

1 Answer 1

2

I think this is simpler,

while True:
    num = int(input("Type a number. "))
    print ()  # blank line before assert whether is or not a even number
    if num % 2 == 0:
        print (num, " is an even number.")
    else:
        print (num, " is an odd number.")

    if input("Would you like to continue?") == 'no':  # Ohh, you want to break now.
        break
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.