-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoger_Beckermeyer_baseball_ch03.py
39 lines (34 loc) · 1.12 KB
/
Roger_Beckermeyer_baseball_ch03.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
#intro
print("================================================================================")
print(" Baseball Team Manager ")
print()
print("MENU OPTIONS")
print("1 - Calculate batting average")
print("2 - Exit program")
print("================================================================================")
#while/if loop for menu options
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 = NumberOfHits / OfficialAtBats
BattingAverage = round(BattingAverage, 3)
BattingAverage = str(BattingAverage)
#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.")
print()
continue