If语句-在Python中使用模运算符嵌套条件

If语句-在Python中使用模运算符嵌套条件,python,if-statement,int,modulus,Python,If Statement,Int,Modulus,我需要用Python创建一个程序,询问用户一个数字,然后告诉用户这个数字是偶数还是可以被5整除。如果两者都不正确,请不要打印任何内容。例如: 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! 我试

我需要用Python创建一个程序,询问用户一个数字,然后告诉用户这个数字是偶数还是可以被5整除。如果两者都不正确,请不要打印任何内容。例如:

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!
我试图复制中使用的方法,但在第8行收到错误消息:

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

因为我使用模运算符来确定Num_1是否是2的精确倍数,所以我应该返回一个值True,因此应该打印“This number is偶数!”,但相反,我得到了这个错误消息-为什么?谢谢

每个Python块的开头应以冒号结尾
。还要注意压痕

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!")

每个Python块的开头应以冒号结尾
。还要注意压痕

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!")

辉煌-不知道Python要求每个块的开头都以冒号结尾。与您对缩进的更正相同-谢谢。Brilliant-不知道Python要求每个块的开头以冒号结尾。与您对缩进的更正相同-谢谢。