一直出现name 'XX' is not defined
本帖最后由 lindalaputa 于 2021-9-7 04:09 编辑def problem1(n):
output = 0
n=input("n=")
if n%2!=0:
output("Hello world")
if n%2==0:
if 2<=n<=5:
output("Goodbye World")
elif 6<=n<=20:
output("Hello World")
elif n>20:
output("Goodbye world")
return(output)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-02da0ae933bd> in <module>
----> 1 assert problem1(3) == "Hello World"
2 assert problem1(2) == "Goodbye World"
3 assert problem1(18) == "Hello World"
NameError: name 'problem1' is not defined output("Hello world")这是什么鬼 把n=input("n=")改成n=int(input("n="))然后再把所有output改成print应该就没问题了 def problem1(n):
if n % 2 != 0:
print("Hello world")
if n % 2 == 0:
if 2 <= n <= 5:
print("Goodbye World")
elif 6 <= n <= 20:
print("Hello World")
elif n > 20:
print("Goodbye world")
problem1(8)
这样有结果,我不知道你为什么要n = input,output的作用是什么 def problem1(n):
output = 0 #这个赋值0是什么意思 表示不懂
n=input("n=")
if n%2!=0:
output("Hello world")#输出函数在python中是 print()
if n%2==0:
if 2<=n<=5:
output("Goodbye World")
elif 6<=n<=20:
output("Hello World")
elif n>20:
output("Goodbye world")
return(output) 我用Python已經一年多了,從來沒有看過 output() 這個函數,請問是新函數嗎?{:5_99:}{:5_99:}
页:
[1]