我尝试将输入放置在函数中,但是当我尝试执行此操作时,它不起作用。 谁能告诉我为什么?
def odd(x):
if x % 2 == 0:
print("this number is even")
else:
print("this number is odd")
print("give a number")
x = input()
a = chance(x)
print(a)
发生此错误:
Traceback (most recent call last):
File "words.py", line 10, in <module>
a = chance(x)
NameError: name 'chance' is not defined
答案 0 :(得分:0)
看看这个,希望你会发现哪里出了问题:
def odd(x):
if int(x) % 2 == 0:
return("this number is even")
else:
return("this number is odd")
x = input("Enter number")
print(odd(x))
祝你好运! :)
要进一步回答“如何在函数中输入内容”这一问题(实际上从来没有做过),您可以这样做,这样会给您相同的结果。
def odd():
x = input("Enter number ")
if int(x) % 2 == 0:
return("this number is even")
else:
return("this number is odd")
print(odd())