-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoger_Beckermeyer_baseball_ch07.py
114 lines (102 loc) · 3.64 KB
/
Roger_Beckermeyer_baseball_ch07.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
############################################
# Class: CPTR 226 - Computer Science I
# Assignment: Case Study ch7
# Author(s): Lee
# Date: 10/13/19
############################################
#imports
from CaseStudyModule import *
#main function
def main():
menu()
while True:
players = read()
UserVariable = int(input("Menu option: "))
if UserVariable == 1:
counter = 1
print("\tPlayer\t\tPOS\tAB\tH\tAVG")
print("---------------------------------------------------------")
for player in players:
print(str(counter) + "\t" + str(player[0]) + "\t\t" + str(player[1]) + "\t" + str(player[2]) + "\t" + str(player[3]) + "\t" + str(player[4]))
counter += 1
print()
if UserVariable == 2:
name = str(input("Name: "))
player = []
player.append(name)
player.append(str(input("Position: ")))
AtBats = int(input("At bats: "))
ErrorCheckerAtBats(AtBats)
player.append(AtBats)
Hits = int(input("Hits: "))
ErrorCheckerHits(AtBats,Hits)
player.append(Hits)
Average = battingaverage(Hits, AtBats)
player.append(float(Average))
players.append(player)
write(players)
print(name, "was added.")
print()
if UserVariable == 3:
number = int(input("Number: "))
number -= 1
print(players[number][0] + " was removed.")
players.pop(number)
write(players)
if UserVariable == 4:
CurrentLineup = int(input("Current lineup number: "))
CurrentLineup -= 1
name = players[CurrentLineup][0]
AB = players[CurrentLineup][2]
H = players[CurrentLineup][3]
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()
if UserVariable == 5:
number = int(input("Number: "))
position = str(input("New Position: "))
number -= 1
player = players[number]
player.pop(1)
player.insert(1,position)
players.pop(number)
players.insert(number, player)
write(players)
print()
if UserVariable == 6:
Lineup = int(input("Lineup Number: "))
Lineup -= 1
name = players[Lineup][0]
AB = players[Lineup][2]
H = players[Lineup][3]
print("You selected", name, "AB=" + str(AB), "H=" + str(H))
AB = int(input("At bats: "))
H = int(input("Hits: "))
player = players[Lineup]
player.pop(2)
player.insert(2,AB)
player.pop(3)
player.insert(3,H)
Average = battingaverage(H, AB)
player.pop(4)
player.insert(4,Average)
players.pop(Lineup)
players.insert(Lineup, player)
write(players)
print(name, "was updated.")
print()
#program exit
if UserVariable == 7:
print("Bye!")
break
#error check
if UserVariable > 7 or UserVariable < 1:
print("Not a valid option. Please try again.")
continue
if __name__ == "__main__":
main()