我正在尝试编写一个程序,提示用户输入一个数字并确定该数字是偶数还是奇数。
remainder = number%2
number = int(input ("number: ")
if remainder == 0
print("Number is even")
else:
print("Number is odd")
我不断收到语法错误。
我正在尝试编写一个程序,提示用户输入一个数字并确定该数字是偶数还是奇数。
remainder = number%2
number = int(input ("number: ")
if remainder == 0
print("Number is even")
else:
print("Number is odd")
我不断收到语法错误。
Python 需要缩进,以及 if 语句后的 :。这是上述内容的更正版本,可以使用:
number = 7
remainder = number%2
if remainder == 0:
print("Number is even")
else:
print("Number is odd")
>>> Number is odd
也就是说,Jane Doe 稍作修改的语法更简洁,并且可能更适合您的应用程序。
def evenOrOdd(number):
if number%2 == 0:
print "Even Number"
else:
print "Odd Number"