Advertisement
ssoni

dict.py

Dec 13th, 2023 (edited)
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. def main():
  2.     players = {'Soto':.284,
  3.                'Judge':.282,
  4.                'Sanchez':.225,
  5.                'Trout':.301,
  6.                'Arraez':.354
  7.     }
  8.  
  9.     while True:
  10.         print('=======================')
  11.         print('1 = Search Database')
  12.         print('2 = Add Player Data')
  13.         print('3 = Find MVP')
  14.         print('4 = Quit')
  15.         action = int(input('Choose action: '))
  16.  
  17.         if action == 1:
  18.             search(players)
  19.         elif action == 2:
  20.             addPlayer(players)
  21.         elif action == 3:
  22.             mvpAvg, mvpName = findMVP(players)
  23.             print(f'{mvpName} is the MVP with an average of {mvpAvg}')
  24.         else:
  25.             break
  26.  
  27. def findMVP(pd):
  28.     maxAvg = 0
  29.     mvp = 'Bugs Bunny'
  30.     for player in pd:
  31.         if pd[player] > maxAvg:
  32.             maxAvg = pd[player]
  33.             mvp = player
  34.     return maxAvg,mvp
  35.  
  36.  
  37. def addPlayer(pd):
  38.     name = input('Player name: ')
  39.     avg = float(input('Avg: '))
  40.     pd[name] = avg
  41.     #pd.update({name:avg})
  42.  
  43. def search(pd):
  44.     player = input('Whose average do you want to look up? ' )
  45.  
  46.     if player == 'all':
  47.         for p in pd:
  48.             print(f'{p} batted {pd[p]}')
  49.     else:
  50.         try:
  51.             print(pd[player])
  52.         except:
  53.             print(f'Player {player} not found')
  54.  
  55. main()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement