Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- players = {'Soto':.284,
- 'Judge':.282,
- 'Sanchez':.225,
- 'Trout':.301,
- 'Arraez':.354
- }
- while True:
- print('=======================')
- print('1 = Search Database')
- print('2 = Add Player Data')
- print('3 = Find MVP')
- print('4 = Quit')
- action = int(input('Choose action: '))
- if action == 1:
- search(players)
- elif action == 2:
- addPlayer(players)
- elif action == 3:
- mvpAvg, mvpName = findMVP(players)
- print(f'{mvpName} is the MVP with an average of {mvpAvg}')
- else:
- break
- def findMVP(pd):
- maxAvg = 0
- mvp = 'Bugs Bunny'
- for player in pd:
- if pd[player] > maxAvg:
- maxAvg = pd[player]
- mvp = player
- return maxAvg,mvp
- def addPlayer(pd):
- name = input('Player name: ')
- avg = float(input('Avg: '))
- pd[name] = avg
- #pd.update({name:avg})
- def search(pd):
- player = input('Whose average do you want to look up? ' )
- if player == 'all':
- for p in pd:
- print(f'{p} batted {pd[p]}')
- else:
- try:
- print(pd[player])
- except:
- print(f'Player {player} not found')
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement