windows - Python 事件

标签 windows python

我正在尝试使用 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/

相关文章:

c - fscanf() 返回负值

python - pymongo中的多个查询

python - Python 的良好实践 : Cutting variable names as parameters

windows - emacs 中的 cygwin shell/Windows 中的 cmd.exe

windows - 如何在 Windows 上使用自定义 couch.ini?

c++ - 线程应用程序中的 sleep 命令

python - python中的矩阵直积保留索引

python - 将 neo4j 查询结果加载到 python 的 `igraph` 图中

python 相当于 matlab unidrnd()

c# - HoloLens 2 对 Windows on ARM 的 gRPC 支持