1

I have been researching for quite a while on this, and I can't figure out what is wrong. I am rather new to Python is general, so it probably an easy fix.

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

The error I get after running it in Idle is the and answering three prompts is the following:

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

Please help, or send me to a post that will help. I tried to find something like this for around an hour.

PM 2Ring
  • 54,345
  • 6
  • 82
  • 182

1 Answers1

1

Did you try this ?

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()
cromod
  • 1,721
  • 13
  • 26