0

I need to create a program in Python that asks the user for a number, then tells the user if that number is even or if it's divisible by 5. If neither is true, do not print anything. For example:

Please enter a number: 5

    This number is divisible by 5!

Please enter a number: 7

Please enter a number: 20

    This number is even!

    This number is divisible by 5!

I tried to copy the method that was used in this answer, but I'm getting an error message on line 8:

SyntaxError: invalid syntax (<string>, line 8) (if Num_1 % 2 == 0)

Here is my code:

#TODO 1: Ask for user input
Num1 = input("Please enter a number")
#TODO 2: Turn input into integer
Num_1 = int(Num1)
#TODO 2: Use conditionals to tell the user whether or not their
#number is even and/or divisible by 5

if Num_1 % 2 == 0
    print ("This number is even!")
        if Num_1 % 5 == 0 
            print ("This number is divisible by 5!")

Since I'm using the modulus operator to determine whether or not Num_1 is an exact multiple of 2, I should be returning a value of True and therefore should print "This number is even!" But instead I'm getting this error message - why? Thanks!

1 Answer 1

2

The start of each Python block should end with a colon :. Also take note of the indentation.

Num1 = input("Please enter a number")
Num_1 = int(Num1)

if Num_1 % 2 == 0:
    print ("This number is even!")
    if Num_1 % 5 == 0:
        print ("This number is divisible by 5!")
Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant - didn't know that Python requires the start of each block to end with a colon. Same with your correction to the indentation - thank you.

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.