# Attribute Error with reversed() in Python

**URL:** <https://forum.freecodecamp.org/t/attribute-error-with-reversed-in-python/390744>\
**Category:** General\
**Created:** [May 18, 2020, 6:15pm UTC](https://forum.freecodecamp.org/t/attribute-error-with-reversed-in-python/390744 "2020-05-18T18:15:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelnicol](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/michaelnicol/32/224831_2.png) [@michaelnicol](https://forum.freecodecamp.org/u/michaelnicol)\
**Post date:** [May 18, 2020, 6:15pm UTC](https://forum.freecodecamp.org/t/attribute-error-with-reversed-in-python/390744/1 "2020-05-18T18:15:37Z")

</div>

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: [https://repl.it/@Michael\_Nicol/hwk4py](https://repl.it/@Michael_Nicol/hwk4py)

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.

```auto
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
'''
print(menu)

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

while not done:
  scores.sort() 
  scores.reversed()
  selection = input("Choice: ")
  if selection == "1":
    done = True
    print("Program Exited")
    break;
  elif selection == "2":
    print()
    for i in scores:
      print("\t", i)
    print()
  elif selection == "3":
    single_score = input("Input a score: ") 
    try:
      single_score = float(single_score) # Check if input is a number
    except:
      "Error: Inputted value is not a number" # Errors if not number
    else:
      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
  else:
    print("Error: Bad Choice") # Bad selection choice
  print("-----------------------") # For formatting

```

---

<div class="post-metadata">

**Author:** ![sfiquet](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sfiquet/32/67130_2.png) [@sfiquet](https://forum.freecodecamp.org/u/sfiquet)\
**Post date:** [May 18, 2020, 6:50pm UTC](https://forum.freecodecamp.org/t/attribute-error-with-reversed-in-python/390744/2 "2020-05-18T18:50:05Z")

</div>

`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](https://global.discourse-cdn.com/freecodecamp/original/3X/5/8/58fc06d8e3fde454b2f5c207796c886e926f7f18.png)

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

---

<div class="post-metadata">

**Author:** ![ML\_enthusiast](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ml_enthusiast/32/135235_2.png) [@ML\_enthusiast](https://forum.freecodecamp.org/u/ML_enthusiast)\
**Post date:** [May 18, 2020, 9:41pm UTC](https://forum.freecodecamp.org/t/attribute-error-with-reversed-in-python/390744/3 "2020-05-18T21:41:04Z")

</div>

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

```auto
scores.reverse()

```

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

```auto
scores.append(float(single_score))

```

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

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:53pm UTC](https://forum.freecodecamp.org/t/attribute-error-with-reversed-in-python/390744/4 "2021-06-01T18:53:26Z")

</div>

Closed on June 1, 2021, 6:53pm UTC


