SimeonTs

SUPyF2 Dictionaries-Lab - 02. Stock

Oct 23rd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. """
  2. Dictionaries - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1736#1
  4.  
  5. SUPyF2 Dictionaries-Lab - 02. Stock
  6.  
  7. Problem:
  8. After you have successfully completed your first task, your boss decides to give you another one right away.
  9. Now not only you have to keep track of the stock, but also you have to answer customers
  10. if you have some products in stock or not.
  11. You will be given key-value pairs of products and quantities (on a single line separated by space).
  12. On the next line you will be given products to search for. Check for each product, you have 2 possibilities:
  13. • If you have the product, print "We have {quantity} of {product} left"
  14. • Otherwise, print "Sorry, we don't have {product}"
  15.  
  16. Examples:
  17. Input:
  18. cheese 10 bread 5 ham 10 chocolate 3
  19. jam cheese ham tomatoes
  20.  
  21. Output:
  22. Sorry, we don't have jam
  23. We have 10 of cheese left
  24. We have 10 of ham left
  25. Sorry, we don't have tomatoes
  26. """
  27.  
  28. string_to_list = [item for item in input().split()]
  29.  
  30. bakery = {}
  31.  
  32. for key in range(0, len(string_to_list), 2):
  33.     item = string_to_list[key]
  34.     value = int(string_to_list[key + 1])
  35.     bakery[item] = value
  36.  
  37. for request in [item for item in input().split()]:
  38.     if request in bakery:
  39.         print(f"We have {bakery[request]} of {request} left")
  40.     else:
  41.         print(f"Sorry, we don't have {request}")
Add Comment
Please, Sign In to add comment