NameError: name 'age' is not defined
NameError: name 'age' is not defined
我研究了好久,一直搞不明白哪里出了问题。我对 Python 比较陌生,所以它可能很容易修复。
def main():
age = 0;
weight = 0;
birthMonth = " ";
getAge();
getWeight();
getBirth();
correct();
def getAge():
age = input("Guess the age.\t")
return age;
def getWeight():
weight = input("Guess the weight.\t")
return weight;
def getBirth():
birthMonth = input("Guess the month.\t")
return birthMonth;
def correct():
if (age <= 25):
print ("Congratulations, the age is 25 or less")
else:
print ("You did not correctly guess the age");
if (weight <= 128):
print ("Congratulations, the weight is 128 or more")
else:
print ("You did not correctly guess the weight");
if (birthMonth == 25):
print ("Congratulations, the month is April")
else:
print ("You did not correctly guess the month");
main();
我在空闲 运行 后得到的错误是,回答三个提示如下:
Traceback (most recent call last):
line 39, in <module>
main();
line 9, in main
correct();
line 24, in correct
if (age <= 25):
NameError: name 'age' is not defined
请帮助,或将我发送到 post 会有帮助。我花了大约一个小时试图找到类似的东西。
你试过了吗?
def main():
age = getAge()
weight = getWeight()
birthMonth = getBirth()
correct(age,weight,birthMonth)
def getAge():
age = float(input("Guess the age.\t"))
return age
def getWeight():
weight = float(input("Guess the weight.\t"))
return weight
def getBirth():
birthMonth = input("Guess the month.\t")
return birthMonth
def correct(age,weight,birthMonth):
if age <= 25:
print ("Congratulations, the age is 25 or less")
else:
print ("You did not correctly guess the age")
if weight <= 128:
print ("Congratulations, the weight is 128 or more")
else:
print ("You did not correctly guess the weight")
if birthMonth == "April":
print ("Congratulations, the month is April")
else:
print ("You did not correctly guess the month")
main()
我研究了好久,一直搞不明白哪里出了问题。我对 Python 比较陌生,所以它可能很容易修复。
def main():
age = 0;
weight = 0;
birthMonth = " ";
getAge();
getWeight();
getBirth();
correct();
def getAge():
age = input("Guess the age.\t")
return age;
def getWeight():
weight = input("Guess the weight.\t")
return weight;
def getBirth():
birthMonth = input("Guess the month.\t")
return birthMonth;
def correct():
if (age <= 25):
print ("Congratulations, the age is 25 or less")
else:
print ("You did not correctly guess the age");
if (weight <= 128):
print ("Congratulations, the weight is 128 or more")
else:
print ("You did not correctly guess the weight");
if (birthMonth == 25):
print ("Congratulations, the month is April")
else:
print ("You did not correctly guess the month");
main();
我在空闲 运行 后得到的错误是,回答三个提示如下:
Traceback (most recent call last):
line 39, in <module>
main();
line 9, in main
correct();
line 24, in correct
if (age <= 25):
NameError: name 'age' is not defined
请帮助,或将我发送到 post 会有帮助。我花了大约一个小时试图找到类似的东西。
你试过了吗?
def main():
age = getAge()
weight = getWeight()
birthMonth = getBirth()
correct(age,weight,birthMonth)
def getAge():
age = float(input("Guess the age.\t"))
return age
def getWeight():
weight = float(input("Guess the weight.\t"))
return weight
def getBirth():
birthMonth = input("Guess the month.\t")
return birthMonth
def correct(age,weight,birthMonth):
if age <= 25:
print ("Congratulations, the age is 25 or less")
else:
print ("You did not correctly guess the age")
if weight <= 128:
print ("Congratulations, the weight is 128 or more")
else:
print ("You did not correctly guess the weight")
if birthMonth == "April":
print ("Congratulations, the month is April")
else:
print ("You did not correctly guess the month")
main()