Attribute Error with reversed() in Python

I am doing a program for a command line interface and am having a issue getting a error when trying to use reverse and sort.

Here is my program:

I also pasted it below.

May seem like a lot, but the only error and issue I am having is with line 25. I tried both reverse() and reversed() and nothing is working. I keep getting this error despite me being correct according to read documentation.

menu = '''
Scoring Engine V2.0.1

1. Press 1 to exit
2. Press 2 to display scores from highest to lowest
3. Press 3 to add a score to the list
4. Press 4 to just show highest and lowest scores

done = False
scores = [85.3, 85.2, 21.99] # Starting scores

while not done:
  selection = input("Choice: ")
  if selection == "1":
    done = True
    print("Program Exited")
  elif selection == "2":
    for i in scores:
      print("\t", i)
  elif selection == "3":
    single_score = input("Input a score: ") 
      single_score = float(single_score) # Check if input is a number
      "Error: Inputted value is not a number" # Errors if not number
      single_score = '{0:.{1}f}'.format(single_score, 2) # Cuts off to 100th place
      scores.append(single_score) # Adds to score list
  elif selection == "4":
    print("Highest: ", scores[0])
    print("Lowest: ", scores[len(scores)-1]) # Length of array - 1 for last item
    print("Error: Bad Choice") # Bad selection choice
  print("-----------------------") # For formatting

reverse works. What doesn’t work is inputting a score. This is what I get after changing reversed to reverse:

Screenshot 2020-05-18 at 19.46.12

Your initial scores are stored as floats but the new value is stored as a string, so the comparison done by sort fails.

1 Like

Here are some bugs in your code
At line 25 , use this code instead.I tested it and works fine


Next bug is at line 44.You are appending a string to the list and then applying sort at the start of list and this throws an error.Here is the simplest way to make it working


I ran the code and checked it for various options.Works fine.Hope this is helpful

1 Like