gpt4 book ai didi

python - Python 代码错误

转载 作者:行者123 更新时间:2023-11-30 22:31:28 24 4
gpt4 key购买 nike

我是 python 的绝对初学者,我的代码中有一个错误。我使用 python 终端来做这件事。我知道这可能很简单,但作为新人,我无法弄清楚。我的代码是:

num = input("Enter a number: ") ;\
... mod = num % 2 ;\
... if mod > 0:

错误是:

File "<stdin>", line 3
if mod > 0:
^

最佳答案

这是因为您需要将输入发送到下一行的 input 函数。此外,使用 Python 3 input,您需要将输入转换为数字数据类型。做这样的事情。

num = int(input("Enter a number: ")) 
5
mod = num % 2
if mod > 0:
print(mod)

关于python - Python 代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45810835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com