-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathQuestion34.py
More file actions
61 lines (56 loc) · 1.98 KB
/
Copy pathQuestion34.py
File metadata and controls
61 lines (56 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Question
# 34. Write a program to repeatedly ask user to enter a team name and now many games the team has won or last.
# c. Using dictionary, allow the user to enter team name and print out the team’s win percentage.
# d. Using it to create a list whose entries are the number of runs of each team.
# e. Using dictionary create a list of all teams having winning records.
# Code
t = {}
while True:
a = input("Team name, wins, looses seprated by commas. Press n to finish entering!:\n")
if a == "n" or a.replace(" ","").strip() == "": break
al = [i.strip() for i in a.split(",")]
t[al[0]] = {"wins":int(al[1]),"looses":int(al[2])}
for key, value in t.items():
print(key+'\'s win precentage:', "{}%".format((value["wins"]/(value["wins"]+value["looses"]))*100))
print()
runs = []
for key in t.keys(): runs.append(int(input(key+'\'s runs:\n')))
print(runs)
print()
wins = {}
for key, value in t.items():
wins[key] = value["wins"]
print("wins:",wins)
# Input
# Team name, wins, looses seprated by commas. Press n to finish entering!:
# sdqwedqd, 3, 1
# Team name, wins, looses seprated by commas. Press n to finish entering!:
# wedwedw, 2, 1
# Team name, wins, looses seprated by commas. Press n to finish entering!:
# qedqdwd, 1, 5
# Team name, wins, looses seprated by commas. Press n to finish entering!:
# qwdqwd, 6, 0
# Team name, wins, looses seprated by commas. Press n to finish entering!:
# efweffwe, 3, 3
# Team name, wins, looses seprated by commas. Press n to finish entering!:
#
# sdqwedqd's win precentage: 75.0%
# wedwedw's win precentage: 66.66666666666666%
# qedqdwd's win precentage: 16.666666666666664%
# qwdqwd's win precentage: 100.0%
# efweffwe's win precentage: 50.0%
#
# sdqwedqd's runs:
# 3
# wedwedw's runs:
# 4
# qedqdwd's runs:
# 5
# qwdqwd's runs:
# 6
# efweffwe's runs:
# 1
# [3, 4, 5, 6, 1]
#
# {'sdqwedqd': 3, 'wedwedw': 2, 'qedqdwd': 1, 'qwdqwd': 6, 'efweffwe': 3}
# Additional Comments