Advertisement
SimeonTs

SUPyF2 Dict-Exercise - 02. A Miner Task

Oct 24th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. """
  2. Dictionaries - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1737#1
  4.  
  5. SUPyF2 Dict-Exercise - 02. A Miner Task
  6.  
  7. Problem:
  8. You will be given a sequence of strings, each on a new line. Every odd line on the console
  9. is representing a resource (e.g. Gold, Silver, Copper, and so on) and every even – quantity.
  10. Your task is to collect the resources and print them each on a new line.
  11. Print the resources and their quantities in the following format:
  12. {resource} –> {quantity}
  13. The quantities will be in the range [1 … 2 000 000 000]
  14. Examples
  15. Input
  16. Gold
  17. 155
  18. Silver
  19. 10
  20. Copper
  21. 17
  22. stop
  23.  
  24. Output:
  25. Gold -> 155
  26. Silver -> 10
  27. Copper -> 17
  28.  
  29. Input:
  30. gold
  31. 155
  32. silver
  33. 10
  34. copper
  35. 17
  36. gold
  37. 15
  38. stop
  39.  
  40. Output:
  41. gold -> 170
  42. silver -> 10
  43. copper -> 17
  44. """
  45. resources = {}
  46.  
  47. while True:
  48.     resource = input()
  49.     if resource == "stop":
  50.         break
  51.     quantity = int(input())
  52.     if resource not in resources:
  53.         resources[resource] = quantity
  54.     else:
  55.         resources[resource] += quantity
  56.  
  57. for resource, quantity in resources.items():
  58.     print(f"{resource} -> {quantity}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement