Heres what I have roster = {} for i in range(5): jersey_number = int(input(f"Enter player{i+1}'s jersey number:\n")) rating = int(input(f"Enter player{i+1}'s rating:\n")) roster[jersey_number] = rating sorted_keys = sorted(roster.keys()) print("ROSTER") for key in sorted_keys: print(f"Jersey number:{key}, Rating:{roster[key]}") menu = "MENU\na - Add player\nd - Remove player\nu - Update player rating\nr - Output players above a rating\no - Output roster\nq - Quit\n" while True: print(menu) option = input("Choose an option:\n") if option == "a": jersey_number = int(input("Enter a new player's jersey number:")) rating = int(input("Enter the player's rating:\n")) roster[jersey_number] = rating elif option == "d": jersey_number = int(input("Enter a jersey number: ")) if jersey_number in roster: del roster[jersey_number] else: print("Jersey number not found.") elif option == "u": jersey_number = int(input("Enter a jersey number:\n")) if jersey_number in roster: rating = int(input("Enter a new rating for player:\n")) roster[jersey_number] = rating else: print("Jersey number not found.") elif option == "r": rating = int(input("Enter a rating:\n")) print(f"ABOVE {rating}") for key in roster: if roster[key] > rating: print(f"Jersey number: {key}, Rating: {roster[key]}") elif option == "o": sorted_keys = sorted(roster.keys()) print("ROSTER") for key in sorted_keys: print(f"Jersey number: {key}, Rating: {roster[key]}") elif option == "q": break else: print("Invalid option. Please try again.") The output gives me lots of new line issues
Heres what I have
roster = {}
for i in range(5):
jersey_number = int(input(f"Enter player{i+1}'s jersey number:\n"))
rating = int(input(f"Enter player{i+1}'s rating:\n"))
roster[jersey_number] = rating
sorted_keys = sorted(roster.keys())
print("ROSTER")
for key in sorted_keys:
print(f"Jersey number:{key}, Rating:{roster[key]}")
menu = "MENU\na - Add player\nd - Remove player\nu - Update player rating\nr - Output players above a rating\no - Output roster\nq - Quit\n"
while True:
print(menu)
option = input("Choose an option:\n")
if option == "a":
jersey_number = int(input("Enter a new player's jersey number:"))
rating = int(input("Enter the player's rating:\n"))
roster[jersey_number] = rating
elif option == "d":
jersey_number = int(input("Enter a jersey number: "))
if jersey_number in roster:
del roster[jersey_number]
else:
print("Jersey number not found.")
elif option == "u":
jersey_number = int(input("Enter a jersey number:\n"))
if jersey_number in roster:
rating = int(input("Enter a new rating for player:\n"))
roster[jersey_number] = rating
else:
print("Jersey number not found.")
elif option == "r":
rating = int(input("Enter a rating:\n"))
print(f"ABOVE {rating}")
for key in roster:
if roster[key] > rating:
print(f"Jersey number: {key}, Rating: {roster[key]}")
elif option == "o":
sorted_keys = sorted(roster.keys())
print("ROSTER")
for key in sorted_keys:
print(f"Jersey number: {key}, Rating: {roster[key]}")
elif option == "q":
break
else:
print("Invalid option. Please try again.")
The output gives me lots of new line issues
Step by step
Solved in 6 steps