Requirements: Your program should provide a menu driven interface in which the user can do the following:
- Choose to exit
- Choose to display the scores from highest to lowest values.
- Choose to add a score to the list. Note that scores must be floating point numbers.
- Choose to display the highest and lowest scores.
I am a definitely a novice at coding and very lost on what to do.
menu = """
1: Exit
2: List scores so far
3: Add a score
4: Display the highest and lowest scores
"""
list1 = ['85.3','85.2','21.99']
done = False
while not done:
print()
print()
print("Scoring Engine")
print()
print(menu)
selection = input("Please enter a selection between 1 and 4: ")
print()
if selection == "1": #exit
done = True
elif selection == "2": #list scores so far
list1 = [float(i) for i in list1]
list1.sort(reverse=True)
print("Scores recorded so far: ")
print()
print(*list1, sep="\n")
elif selection == "3": #adds a score
print()
new_score = input("Please enter a score between 0 and 100: ")
try:
new_score = float(new_score)
except ValueError:
print()
print("Please enter a valid score between 0 and 100.")
continue
if float(new_score)<0:
print()
print("{:.2f} is too low. Scores must be between 0 and 100".format(new_score))
elif float(new_score)>100:
print()
print("{:.2f} is too high. Scores must be between 0 and 100".format(new_score))
else:
list1.append(new_score)
print("Score added")
Problem: When I add a score and then go back to option 2 I get:
Traceback (most recent call last):
File "C:\Users\******\Desktop\hwk4.py", line 36, in <module>
list1.sort(reverse=True)
TypeError: '<' not supported between instances of 'str' and 'float'
Is there a way to get the appended values to be sorted when selecting option 2?