我有一个简单的代码如下。
finished = True
def number():
x = int(input("Please enter a number \n"))
m = x%2
if m>0:
print("Odd")
finished = True
else:
print("Even")
finished = True
while finished:
number()
当我运行代码时,它显示了一个问题
at line 6: if m > 0:
NameError: name 'm' is not defined.
想知道如何解决这个问题?
答案 0 :(得分:2)
只需在你的函数中移动你的if语句。
def number():
x = int(input("Please enter a number \n"))
m = x%2
if m>0:
print("Odd")
finished = True
else:
print("Even")
finished = True