NameError:未定义名称'age'

时间:2016-02-07 09:22:32

标签: python python-3.x nameerror

我已经研究了很长一段时间,我无法弄清楚出了什么问题。我对Python很陌生,所以它可能很容易解决。

// both print "ABC"
print(try stringFromUTF8BytesGeneric([65, 66, 67]))
print(try stringFromUTF8BytesGeneric(ContiguousArray<UInt8>([65, 66, 67])))

在空闲状态下运行后得到的错误是,并且回答以下三个提示:

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();

请帮忙,或将我发送给有帮助的帖子。我试着在一个小时左右找到这样的东西。

1 个答案:

答案 0 :(得分:1)

你试过这个吗?

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()