【问题标题】:Question, why is my program not processing when I call the checkInteger function?问题,为什么当我调用 checkInteger 函数时我的程序没有处理?
【发布时间】:2020-01-31 02:42:59
【问题描述】:

为什么我调用 checkInteger 函数时程序没有处理?

def main():
    print("Kaylees Prime Number Checker")
    numChoice = int(input("Please type a number: "))
    checkInteger()

def checkInteger(numChoice):
    if number % 2 == 0:
        print("Your number is not prime. ")
    else:
        print("Your number is prime.")

main()

【问题讨论】:

  • 请格式化您的代码。另外,请澄清“不处理”的含义。据我所知,这段代码应该抛出异常;是这样吗?
  • 我的程序会打印出“Kaylees Prime Number Checker”,然后会询问请输入一个数字,然后告诉我缺少 1 个必需的位置参数:“数字”。我看到你们说我需要争论,但我不明白。

标签: python function conditional-statements main statements


【解决方案1】:

看起来你需要一个 checkInteger 的参数,你也应该命名你的参数编号,或者将编号更改为 numChoice。无论哪种方式,它必须是相同的

【讨论】:

    【解决方案2】:

    您必须将参数传递给函数 checkInteger,因为它被定义为在您的定义中采用一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-03
      • 2019-09-26
      • 1970-01-01
      相关资源
      最近更新 更多