-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoger_Beckermeyer_baseball_ch04.py
More file actions
66 lines (55 loc) · 1.78 KB
/
Roger_Beckermeyer_baseball_ch04.py
File metadata and controls
66 lines (55 loc) · 1.78 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
############################################
# Class: CPTR 226 - Computer Science I
# Assignment: Case Study ch_3
# Author(s): Lee
# Date: 9/22/19
############################################
#menu function
def menu():
print("================================================================================")
print(" Baseball Team Manager ")
print()
print("MENU OPTIONS")
print("1 - Calculate batting average")
print("2 - Exit program")
print("================================================================================")
#menu options to display for erros
def MenuOptions():
print("MENU OPTIONS")
print("1 - Calculate batting average")
print("2 - Exit program")
print()
#batting average function
def battingaverage(x,y):
BattingAverage = x / y
BattingAverage = round(BattingAverage, 3)
BattingAverage = str(BattingAverage)
return BattingAverage
#main function
def main():
menu()
while True:
UserVariable = int(input("Menu option: "))
if UserVariable == 1:
#intro
print("Calculating batting average...")
#user input
OfficialAtBats = int(input("Official number of at bats: "))
NumberOfHits = int(input("Number of hits: "))
#average calculator
BattingAverage = battingaverage(NumberOfHits, OfficialAtBats)
#return batting average
print("Batting average: " + BattingAverage)
print()
continue
#program exit
if UserVariable == 2:
print("Bye!")
break
#error check
else:
print("Not a valid option. Please try again.")
MenuOptions()
continue
if __name__ == "__main__":
main()