I am trying to figure out what is wrong with this code. It says that global variable is not defined. Below is the error and code of the program. I have also highlighted the error place. Please help.
Andy
ERROR
Traceback (most recent call last):
File "F:/Python/Python/Tests/Hardik Desai Test 3A.py", line 43, in -toplevel-
calculate()
File "F:/Python/Python/Tests/Hardik Desai Test 3A.py", line 19, in calculate
area = length * width
NameError: global name 'length' is not defined
Andy
ERROR
Traceback (most recent call last):
File "F:/Python/Python/Tests/Hardik Desai Test 3A.py", line 43, in -toplevel-
calculate()
File "F:/Python/Python/Tests/Hardik Desai Test 3A.py", line 19, in calculate
area = length * width
NameError: global name 'length' is not defined
Code:
def tableOrder():
orderNum = int (raw_input ("Enter the order number: "))
if (orderNum == 0):
print "Thank you for visiting 'Woodchop Shop'\n"
raw_input ("Press Enter to exit!!!")
else:
length = int (raw_input ("Enter the length of the table in inches: "))
width = int (raw_input ("Enter the width of the table in inches: "))
woodType = (raw_input ("Enter type of wood you would like for the table: "))
drawerNum = int (raw_input("Enter the numbers of drawer you would like: "))
def calculate():
global drawerNum, length, width
[B]area = length * width[/B]
baseCharge = 200.00
if area <= 750:
charge1 = baseCharge
elif area > 750:
charge1 = baseCharge + 50.00
if woodType == "mahogany":
charge2 = 150.00
elif woodType == "oak":
charge2 = 125.00
elif woodType == "pine":
charge2 = 0.00
charge3 = drawerNum * 30.00
totalCharge = charge1 + charge2 + charge3
def getOutput():
print "Order Number : ",orderNum
print "Size of Table : ", area
print "Type of Wood : ",woodType
print "Total charge for the table: ",totalCharge
#Main------------------------------------------
global area, length, width
tableOrder()
[B]calculate()[/B]
getOutput
while ans == "y" or ans == "Y":
tableOrder()
calculate()
getOutput()
raw_input("Would you like to order another table?? (y/n)")
raw_input ("Press enter to exit....")
Comment