-3

Not the same question. his issue was with the variable being produced by input. my problem is the variable itself. 'MONTH' is not defined when Month is set to = input. My question: Prompt : # of month born Input ---> 1 January | | name error 'month is not defined' His: Name=input -----> input 'dude' error: 'DUDE IS NOT DEFINED' Not the same at all... He also uses Python 2.xx I'm using 3.4.3

================================ RESTART ================================

day born input day # 1 Traceback (most recent call last): File "C:/Python34/Astrology calc build 2.py", line 43, in print (month) NameError: name 'month' is not defined

def calculate():
    month=input('   # of month born    ')
    if month == '1':
        print ("January")
        return "January"
    elif month == '2':
        print   ("February")
        return "February"
    elif month == '3':
        print  ("March")
        return "March"
    elif month == '4':
        print  ("April")
        return "April"
    elif month == '5':
        print   ("May")
        return "May"
    elif month == '6':
        print("June")
        return ("June")
    elif month == '7':
        print ("July")
        return "July"
    elif month == '8':
        print("August")
        return "August"
    elif month == '9':
        print("september")
    return "September"
    elif month == '10':
        print("October")
        return "October"
    elif month == '11':
        print ("November")
        return "November"
    elif month == '12':
        return "December"
        print ("December")
    else:
        return calculate()
print('day born')
day=input(' input day #    ')
print (month)
calculate()
Er Rds
  • 31
  • 1
  • 2
  • @CoryKramer Not the same question. his issue was with the variable being produced by input. my problem is the variable itself. 'MONTH' is not defined when Month is set to = input. My question: Prompt : # of month born Input ---> 1 January | | name error 'month is not defined' His: Name=input -----> input 'dude' error: 'DUDE IS NOT DEFINED' Not the same at all... He also uses Python 2.xx I'm using 3.4.3 – Er Rds Sep 09 '15 at 20:41
  • `month` is not global, you cannot access `month` here as it's defined in `calculate()` and you call `calculate` after print `month` – Hacketo Sep 11 '15 at 19:00
  • 1
    BTW `import calendar; print calendar.month_name[3]` will print March – philshem Sep 11 '15 at 21:08

1 Answers1

0

These 4 lines are executed first:

print('day born')
day=input(' input day #    ')
print (month)
calculate()

So in your print (month) command (line 3), month has not yet been defined.

Also, if you want to print what calculate() returns, in addition to printing in calculate(), then you need to print (calculate()) or set the response of the function to a variable, and print it later

philshem
  • 24,761
  • 8
  • 61
  • 127