Home > Blockchain >  it says NameError: name 'Doctor' is not defined when I try to execute
it says NameError: name 'Doctor' is not defined when I try to execute

Time:11-16

#Program that outputs quote for 3 jobs and outputs a sorry message >if an unrecognised job is used

#Subroutine to describe job
def Desc(Job):
    if Job == 1:
        print("Seeing what other people cant see gives you great vision")
    elif Job == 2:
        print("Logical thinking, passion and perseverance is the paint on your palette.")
    elif Job == 3:
        print("The engineer has been,and is,a maker of history.")
    else:
        print("Sorry, we could not find a quote for your job")

Analyst = 1
Developer = 2
Engineer = 3

#Main program
Desc(Doctor)

CodePudding user response:

Assuming that this is all of the code, your error is caused because you do not have a variable defined that is called Doctor, so when you call Desc(Doctor) it cannot find a variable with that name. If you are going to use Doctor you need to define a variable with that name.

Edit to change my answer for what the poster is trying to do:

def Desc(Job):
   if Job == 'Analyst':
       print("Seeing what other people cant see gives you great vision")
   elif Job == 'Developer':
       print("Logical thinking, passion and perseverance is the paint on your palette.")
   elif Job == 'Engineer':
       print("The engineer has been,and is,a maker of history.")
   else:
       print("Sorry, we could not find a quote for your job")
    

Then you call your function like this:

Desc('Doctor')

CodePudding user response:

You did not set a variable 'Doctor'. You need write for example:

Doctor = 1
Desc(Doctor)
  • Related