-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoger_Beckermeyer_baseball_ch14.py
More file actions
116 lines (103 loc) · 3.83 KB
/
Roger_Beckermeyer_baseball_ch14.py
File metadata and controls
116 lines (103 loc) · 3.83 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
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
############################################
# Class: CPTR 226 - Computer Science I
# Assignment: Case Study ch11
# Author(s): Lee
# Date: 11/10/19
############################################
#imports
from CaseStudyModule import *
from CaseStudyModule_ReadAndWrite import *
from CaseStudyModule_PlayerClass import Player
#main function
def main():
menu()
while True:
players = read()
try:
UserVariable = int(input("Menu option: "))
except Exception as e:
print("Not a valid option. Please try again.")
continue
if UserVariable == 1:
print("{:>9} {:>30} {:>7} {:>7} {:>7}".format("Player", "POS", "AB", "H", "AVG"))
print("-" * 64)
PlayerFormat = "{:<2} {:<30} {:>6} {:>7} {:>7} {:>7}"
counter = 1
for player in players:
Name = str(player.FirstName) + " " + str(player.LastName)
Position = player.Position
AB = player.AtBats
Hits = player.Hits
Average = battingaverage(int(Hits), int(AB))
print(PlayerFormat.format(counter,Name,Position,AB,Hits,Average))
counter += 1
print()
elif UserVariable == 2:
FirstName = str(input("First Name: "))
LastName = str(input("Last Name: "))
Position = (str(input("Position: ")))
AtBats = int(input("At bats: "))
ErrorCheckerAtBats(AtBats)
Hits = int(input("Hits: "))
ErrorCheckerHits(AtBats,Hits)
player = Player(FirstName,LastName,Position,AtBats,Hits)
players.append(player)
write(players)
print(FirstName + " " + LastName + " " + " was added.")
print()
continue
elif UserVariable == 3:
number = int(input("Number: "))
number -= 1
player = players[number]
print(player.FirstName + " was removed.")
players.pop(number)
write(players)
continue
if UserVariable == 4:
CurrentLineup = int(input("Current lineup number: "))
CurrentLineup -= 1
name = players[CurrentLineup].FirstName
AB = players[CurrentLineup].AtBats
H = players[CurrentLineup].Hits
print("You selected", name, "AB=" + str(AB), "H=" + str(H))
player = players[CurrentLineup]
players.pop(CurrentLineup)
NewLineup = int(input("New lineup number: "))
NewLineup -= 1
players.insert(NewLineup, player)
write(players)
print()
continue
elif UserVariable == 5:
number = int(input("Number: "))
number -= 1
position = str(input("New Position: "))
players[number].Position = position
write(players)
print()
continue
elif UserVariable == 6:
player = []
Lineup = int(input("Lineup Number: "))-1
name = players[Lineup].FirstName
AB = players[Lineup].AtBats
H = players[Lineup].Hits
print("You selected", name, "AB=" + str(AB), "H=" + str(H))
AB = int(input("At bats: "))
H = int(input("Hits: "))
player = players[Lineup]
player.AtBats = AB
player.Hits = H
write(players)
print(name, "was updated.")
print()
continue
elif UserVariable == 7:
print("Bye!")
break
elif UserVariable < 1 or UserVariable > 7:
print("Not a valid option. Please try again.")
continue
if __name__ == "__main__":
main()