Advertisement
Spocoman

PC Game Shop

Mar 15th, 2022 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. volume = int(input())
  2. hearthstones = 0
  3. fornites = 0
  4. overwatches = 0
  5. others = 0
  6.  
  7. for i in range(volume):
  8.     game = input()
  9.     if game == "Hearthstone":
  10.         hearthstones += 1
  11.     elif game == "Fornite":
  12.         fornites += 1
  13.     elif game == "Overwatch":
  14.         overwatches += 1
  15.     else:
  16.         others += 1
  17.  
  18. print(f"Hearthstone - { hearthstones / volume * 100:.2f}%")
  19. print(f"Fornite - { fornites / volume * 100:.2f}%")
  20. print(f"Overwatch - { overwatches / volume * 100:.2f}%")
  21. print(f"Others - { others / volume * 100:.2f}%")
  22.  
  23. РЕШЕНИЕ С РЕЧНИК И ТЕРНАРЕН ОПЕРАТОР:
  24.  
  25. games = {'Hearthstone': 0, 'Fornite': 0, 'Overwatch': 0, 'Others': 0}
  26. volume = int(input())
  27.  
  28. for i in range(volume):
  29.     game = input()
  30.     games[game if game in games else 'Others'] += 1
  31.  
  32. for game in games:
  33.     print(f"{game} - {games[game] / volume * 100:.2f}%")
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement