-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
135 lines (113 loc) · 3.9 KB
/
app.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import constants
import random
import copy
replay = []
replayed = 1
my_teams = copy.deepcopy(constants.TEAMS)
my_players = copy.deepcopy(constants.PLAYERS)
store_cleaned_players = []
def menu():
game_running = True
while game_running:
try:
menu_choice = int(input("""
BASKETBALL TEAM STATS TOOL
-----------MENU-----------
Here are your choices:
1) Display Team Stats
2) Quit
Enter an option > """))
if menu_choice == 1:
choose_team()
game_running = False
if menu_choice == 2:
print("Goodbye")
exit()
if menu_choice > 2:
raise ValueError
if menu_choice < 1:
raise ValueError
except ValueError:
print("Please choose a valid option")
def choose_team():
game_running = True
while game_running:
try:
team_choice = int(input("""
1) Panthers
2) Bandits
3) Warriors
Enter an option > """))
if team_choice == 1:
team_choice_answer = "Panthers"
display_stats(team_choice_answer)
game_running = False
if team_choice == 2:
team_choice_answer = "Bandits"
display_stats(team_choice_answer)
game_running = False
if team_choice == 3:
team_choice_answer = "Warriors"
display_stats(team_choice_answer)
game_running = False
if team_choice > 3:
raise ValueError
if team_choice < 1:
raise ValueError
except ValueError:
print("Please choose a valid option")
def clean_data():
if len(replay) == 0:
cleaned_players = []
for data in my_players:
add_player_data = {}
add_player_data['name'] = data['name']
if data['experience'] == 'YES':
add_player_data['experience'] = True
else:
add_player_data['experience'] = False
add_player_data["height"] = int(data['height'].split(' ')[0])
cleaned_players.append(add_player_data)
else:
cleaned_players = store_cleaned_players[0].copy()
return cleaned_players
def balance_teams():
cleaned_players = clean_data()
each_team_total = int(len(cleaned_players) / len(my_teams))
if len(replay) == 0:
shuffled_players = random.shuffle(cleaned_players)
store_cleaned_players.append(cleaned_players.copy())
player_names = []
for player in cleaned_players:
add_player_data = {}
add_player_data = player["name"]
player_names.append(add_player_data)
panthers = []
panthers.append(player_names[0:each_team_total])
bandits = []
bandits.append(player_names[each_team_total:each_team_total * 2])
warriors = []
warriors.append(player_names[each_team_total * 2:each_team_total * 3])
return panthers, bandits, warriors, each_team_total
def display_stats(team_name):
panthers, bandits, warriors, total_players = balance_teams()
if team_name == "Panthers":
player_names = ', '.join(panthers[0][0:total_players])
if team_name == "Bandits":
player_names = ', '.join(bandits[0][0:total_players])
if team_name == "Warriors":
player_names = ', '.join(warriors[0][0:total_players])
choice = input("""
Team {} Stats:
--------------
Total players: {}
Players:
{}
Press ENTER to continue... """.format(team_name, total_players, player_names))
if choice == "":
replay.append(replayed)
menu()
else:
exit()
if __name__ == "__main__":
menu()