0

I'm getting this error from the code, "UnboundLocalError: local variable 'lowest' referenced before assignment". Why am I getting this? What does 'referenced before assignment' in this case really mean? Because I think that I assign the variable 'lowest' only after 'scores' variable is defined. Any help would be appreciated.

def main():
 scores = get_score()
 total = get_total(scores)
 lowest -= min(scores)
 average = total / (len(scores) - 1)
 print('The average, with the lowest score dropped is:', average)
def get_score():
 test_scores = []
 again = 'y'
 while again == 'y':
 value = float(input('Enter a test score: '))
 test_scores.append(value)
 print('Do you want to add another score? ')
 again = input('y = yes, anything else = no: ')
 print()
 return test_scores
def get_total(value_list):
 total = 0.0
 for num in value_list:
 total += num
 return total
main()
asked Dec 6, 2013 at 22:04

3 Answers 3

3

You're using -=, which requires a starting value. But you don't provide a starting value. In context it looks like you meant to use = instead.

answered Dec 6, 2013 at 22:07
Sign up to request clarification or add additional context in comments.

Comments

3

That's because in main() you are saying

lowest -= min(scores)

which is essentially lowest = lowest - min(scores). Since you don't have lowest set previously, you'll get that error

answered Dec 6, 2013 at 22:08

1 Comment

Thanks for the help. I either didn't see it or should go to my bed now. :)
1

Your lowest variable is not defined. You use "lowest -= min(scores)" which means subtract min(scores) from lowest, but lowest doesn't exist yet. Based on the name of the variable I'm guessing you want to do:

def main():
 scores = get_score()
 total = get_total(scores)
 lowest = min(scores)
 average = total / (len(scores) - 1)
 print('The average, with the lowest score dropped is:', average)
answered Dec 6, 2013 at 22:09

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.