Advertisement
SimeonTs

SUPyF2 Lists Basics Exercise - 09. Hello, France

Oct 3rd, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.70 KB | None | 0 0
  1. """
  2. Lists Basics - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1725#8
  4.  
  5. SUPyF2 Lists Basics Exercise - 09. Hello, France (not included in final score)
  6.  
  7. Problem:
  8. The budget was enough to get them to Frankfurt and they have some money left, but their final aim is to go to France,
  9. which means that they will need more finances. They’ve decided to make profit by buying items on discount
  10. from the Thrift Shop and selling them for a higher price. You must help them.
  11. Create a program that calculates the profit after buying some items and selling them on a higher price.
  12. In order to fulfil that, you are going to need certain data -
  13. you will receive a collection of items and a budget in the following format:
  14. {type->price|type->price|type->price……|type->price}
  15. {budget}
  16. The prices for each of the types cannot exceed a certain price, which is given bellow:
  17. Type    Maximum Price
  18. Clothes 50.00
  19. Shoes   35.00
  20. Accessories 20.50
  21. If a price for a certain item is higher than the maximum price, don’t buy it.
  22. Every time you buy an item, you have to reduce the budget with the value of its price.
  23. If you don’t have enough money for it, you can’t buy it. Buy as much items as you can.
  24. You have to increase the price of each of the items you have successfully bought with 40%.
  25. Print the list with the new prices and the profit you will gain from selling the items.
  26. They need exactly 150$ for tickets for the train, so if their budget after selling the products is enough
  27. – print – "Hello, France!" and if not – "Time to go."
  28. Input / Constraints
  29. • On the 1st line you are going to receive the items with their prices in the format described above
  30. – real numbers in the range [0.00……1000.00]
  31. • On the 2nd line, you are going to be given the budget – a real number in the range [0.0….1000.0]
  32. Output
  33. • Print the list with the bought item’s new prices,
  34. rounded 2 digits after the decimal separator in the following format:
  35. "{price1} {price2} {price3} {price5}………{priceN}"
  36. • Print the profit, rounded 2 digits after the decimal separator in the following format:
  37. "Profit: {profit}"
  38. • If the money for tickets are enough, print: "Hello, France!" and if not – "Time to go."
  39.  
  40. Examples:
  41. Input:
  42. Clothes->43.30|Shoes->25.25|Clothes->36.52|Clothes->20.90|Accessories->15.60
  43. 120
  44.  
  45. Output:
  46. 60.62 35.35 51.13
  47. Profit: 42.03
  48. Hello, France!
  49.  
  50. Comments:
  51. We start subtracting the valid prices from the budget:
  52. 120 – 43.40 = 76.7.
  53. 76.7 – 25.25 = 51.45
  54. 51.45 – 36.52 = 14.93
  55. 14.93 is less than 20.90 and 15.60, so we can’t buy either of the last two.
  56. We must increase each price with 40% and the new prices are: 60.62 35.35 51.13.
  57. The profit is 42.03 and their new budget will be – what is left of the budget - 14.93 + {sum of all newPrices}.
  58. It is enough, so we print: Hello, France!
  59.  
  60. Input:
  61. Shoes->41.20|Clothes->20.30|Accessories->40|Shoes->15.60|Shoes->33.30|Clothes->48.60
  62. 90
  63.  
  64. Output:
  65. 28.42 21.84 46.62
  66. Profit: 27.68
  67. Time to go.
  68. """
  69. items = input().split("|")
  70. budget = float(input())
  71. initial_budget = budget
  72.  
  73.  
  74. bought_items = []
  75.  
  76. for item in items:
  77.     name, price = item.split("->")
  78.     price = float(price)
  79.     if budget - price >= 0:
  80.         if (name == "Clothes" and (price <= 50.00)) or \
  81.                 (name == "Shoes" and (price <= 35.00)) or \
  82.                 (name == "Accessories" and (price <= 20.50)):
  83.             budget -= price
  84.             bought_items += [price * 1.4]
  85.  
  86. total = (budget + sum(bought_items))
  87. profit = (total - initial_budget)
  88.  
  89. for item in bought_items:
  90.     print(f"{item:.2f}", end=" ")
  91. print()
  92. print(f"Profit: {profit:.2f}")
  93. if total >= 150:
  94.     print("Hello, France!")
  95. else:
  96.     print("Time to go.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement