-2

How am I supposed to call the workshop and location variables from another defined function? I have to do it this way but whenever I run the program, it tells me the workshop variable is not defined. code:

def main():
print (menu_quest())
print(worklodge_cost())

#Print menu
def menu_quest():
print ('\t\t\tMENU WORKSHOP SELECTOR')
print ('\tWORKSHOPS \tRegistration Fee \tDays')
print ('1) Handling Stress \t$1000 \t\t\t3 ')
print ('2) Time Management\t$800 \t\t\t3 ')
print ('3) Supervision Skills\t$1600 \t\t\t3 ')
print ('4) How to Interview \t$500 \t\t\t1\n')
print ('\tLOCATION \tLodging Fee per Day')
print ('1) Austin \t\t$150')
print ('2) Chicago\t\t$225 ')
print ('3) Phoenix\t\t$175 ')
print ('4) Orlando\t\t$300 ')
workshop = int(input("From the menu, enter the number coresponding to your workshop selection: ")) #asking user to choose from the table
location = int(input("From the menu, enter the number coresponding to the location you will be traveling to: ")) #same as before
return workshop
return location

def worklodge_cost():   
if workshop == 1: #what number the user puts in determines what values they get out of this workshop section
    price = 1000
    amtdays = 3
elif workshop == 2:
    price = 800
    amtdays = 3
elif workshop == 3:
    price = 1600
    amtdays = 3
elif workshop == 4:
    price = 500
    amtdays = 1
    return workshop, price, amtdays


if location == 1: #what number the user puts in determines the price of their lodging
    lodgeprice = 150
elif location == 2:
    lodgeprice = 225
elif location == 3:
    lodgeprice = 175
elif location == 4:
    lodgeprice = 300
totalodging = amtdays * lodgeprice
return totalodging
main()
2
  • 1
    There are some very basic python errors in the code, you should break it down into simpler parts to work out what is happening. For example, you are trying to access a variable inside one function from another function. Basic OO coding doesn't allow that so perhaps do some more learning first because there are lots of different ways to do this. Mar 4, 2022 at 15:51
  • Have a look at dictionnary and arrays it will help you a lot. Mar 7, 2022 at 23:16

1 Answer 1

0

That's because even though you did define it, it was not called properly. First, indentation is so very important in python. Next:

def main():
    menu_quest()
    worklodge_cost()


def menu_quest():
    ...
    return workshop, location


def worklodge_cost():
   ...
    

Call the workshop variable as:

    menu_quest[workshop] *or*
    menu_quest[0]

Do the same thing when calling the variables returned from worklodge_cost()

    worklodge_cost[amtdays]

No need to return workshop or price as price is never called.

    if menu_quest[location] == 1:  *or*
    if menu_quest[1] == 1:

And lastly,

totalodging = worklodge_cost[amtdays] * lodgeprice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.