Team stats using dictionaries in Python: Repeatedly ask the user to enter a team
ID: 3756803 • Letter: T
Question
Team stats using dictionaries in Python: Repeatedly ask the user to enter a team name and how many games the team won and how many they lost. Store this information in a dictionary where the keys are the team names and the values are lists of the form [wins, losses]. (a) Using the dictionary created above, allow the user to enter a team name and print out the team's winning percentage. (b) Using the dictionary, create a list whose entries are the number of wins of each team. (c) Using the dictionary, create a list of all those teams that have winning records.Explanation / Answer
Here is the code in python
..........................................................................................................................................................
# declare a dictionary which will hold all the data
...............................................................................................................................................
Some output samples
Enter Team Name:Mars
Enter wins:12
Enter losses:4
Do you want to add a new team (Y/N)?Y
Enter Team Name:Venus
Enter wins:3
Enter losses:12
Do you want to add a new team (Y/N)?y
Enter Team Name:Earth
Enter wins:7
Enter losses:3
Do you want to add a new team (Y/N)?t
Enter Team Name:Pluto
Enter wins:0
Enter losses:5
Do you want to add a new team (Y/N)?n
Enter team name whose winning percentage you want to calculate:Earth
Team Earth winning percentage is 70.0 %
[12, 3, 7, 0]
['Mars', 'Venus', 'Earth']
Process finished with exit code 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.