How do I fix this? It's just an assignment for school bit it's driving me crazy. low, med, and high are supposed to be initialized at there starting values only once before the loop begins, but it won't work, here's the data.
And here's the traceback:
Traceback (most recent call last):
File "F:\programming \Lab Practicum.py", line 131, in <module>
main()
File "F:\programming \Lab Practicum.py", line 22, in main
addHigh()
File "F:\programming \Lab Practicum.py", line 69, in addHigh
high=high - size * frequency
UnboundLocalErr or: local variable 'high' referenced before assignment
>>>
PLEASE HELP!!!
Code:
def main(): choice = 0 high = 3000.0 med = 5000.0 low = 9000.0 priority = 0 size = 0.0 frequency = 0 while choice != 3: print '1-add a back up' print '2-remove a backup' print '3-exit program' choice = input ('make a selection') if choice == 1: priority = getPriority(priority) if priority == 1: addHigh() elif priority == 2: addMed() elif priority == 3: addLow() else: print 'invalid entry' elif choice == 2: priority = getPriority(priority) if priority == 1: removeHigh() elif priority == 2: removeMed() elif priority == 3: removeLow() else: print 'invalid entry' elif choice == 3: print 'goodbye' else: print'invalid entry' def getPriority(priority): print '1-high priority' print '2-medium priority' print '3-low priority' priority = input ('enter priority') return priority def getSize(): size = input ('enter size in megabytes') return size def getFrequency(): frequency = input ('enter frequency') return frequency def addHigh(): size = getSize() frequency = getFrequency() high=high - size * frequency if high > 0: print 'you have' , high , 'MB left' else: print 'insufficient space' high = high + size * frequency
Traceback (most recent call last):
File "F:\programming \Lab Practicum.py", line 131, in <module>
main()
File "F:\programming \Lab Practicum.py", line 22, in main
addHigh()
File "F:\programming \Lab Practicum.py", line 69, in addHigh
high=high - size * frequency
UnboundLocalErr or: local variable 'high' referenced before assignment
>>>
PLEASE HELP!!!
Comment