我正在尝试使用 Geany 中的一个程序,该程序旨在告诉我一个数字是偶数还是奇数。这是我写的程序。
def activity01(num1):
'''Determine if an input number is Even or Odd'''
if [num1 % 2 == 0]
return 'even'
else:
return 'odd'
谁能告诉我这个程序出了什么问题吗?现在它告诉我第 3 行末尾的语法无效。我正在我通过事件的类(class)的测试环境中运行该程序。
最佳答案
在 if (num1 % 2 == 0) 后面放置一个冒号
。您应该能够在您的函数中使用下面的代码:
def activity01(num1):
"""Determine if an input number is Even or Odd"""
if num1 % 2 == 0:
return "even"
else:
return "odd"
print activity01(3)
print activity01(4)
关于windows - Python 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45644465/