我正在尝试编写一个程序,提示用户输入一个数字&确定数字是偶数还是奇数。
remainder = number%2
number = int(input ("number: ")
if remainder == 0
print("Number is even")
else:
print("Number is odd")
我一直收到语法错误。
答案 0 :(得分:3)
Python需要缩进,以及:if语句之后。以下是上述修正后的版本:
number = 7
remainder = number%2
if remainder == 0:
print("Number is even")
else:
print("Number is odd")
>>> Number is odd
也就是说,Jane Doe略微修改后的语法更清晰,可能更适合您的应用程序。
答案 1 :(得分:3)
def evenOrOdd(number):
if number%2 == 0:
print "Even Number"
else:
print "Odd Number"