Advertisement
SimeonTs

SUPyF2 P.-Mid-Exam/10 March 2019/1 - 02. Hello, France

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