我有一个简单的代码如下。
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.
我想知道如何解决这个问题?
只需在函数中移动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