SimeonTs

SUPyF2 P.-Mid-Exam/16 April 2019 - 01. Easter Cozonacs

Oct 29th, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.79 KB | None | 0 0
  1. """
  2. Technology Fundamentals Retake Mid Exam - 16 April 2019
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1610#0
  4.  
  5. SUPyF2 P.-Mid-Exam/16 April 2019 - 01. Easter Cozonacs
  6.  
  7. Problem:
  8. Since it’s Easter you have decided to make some cozonacs and exchange them for eggs.
  9. Create a program that calculates how much cozonacs you can make with the budget you have.
  10. First, you will receive your budget. Then, you will receive the price for 1 kg flour.
  11. Here is the recipe for one cozonac:
  12. Eggs    1 pack
  13. Flour   1 kg
  14. Milk    0.250 l
  15. The price for 1 pack of eggs is 75% of the price for 1 kg flour.
  16. The price for 1l milk is 25% more than price for 1 kg flour. Notice,
  17. that you need 0.250l milk for one cozonac and the calculated price is for 1l.
  18. Start cooking the cozonacs and keep making them until you have enough budget. Keep in mind that:
  19. • For every cozonac that you make, you will receive 3 colored eggs.
  20. • For every 3rd cozonac that you make,
  21. you will lose some of your colored eggs after you have received the usual 3 colored eggs for your cozonac.
  22. The count of eggs you will lose is calculated when you subtract 2 from your current count of cozonacs –
  23. ({currentCozonacsCount} – 2)
  24. In the end, print the cozonacs you made, the eggs you have gathered and the money you have left,
  25. formatted to the 2nd decimal place, in the following format:
  26. "You made {countOfCozonacs} cozonacs! Now you have {coloredEggs} eggs and {moneyLeft}BGN left."
  27. Input / Constraints
  28. • On the 1st line you will receive the budget – a real number in the range [0.0…100000.0]
  29. • On the 2nd line you will receive the price for 1 kg floor – a real number in the range [0.0…100000.0]
  30. • The input will always be in the right format.
  31. • You will always have a remaining budget.
  32. • There will not be a case in which the eggs become a negative count.
  33. Output
  34. • In the end print the count of cozonacs you have made,
  35.    the colored eggs you have gathered and the money formatted to the 2nd decimal place in the format described above.
  36.  
  37. Examples:
  38. Input:  Output:
  39. 20.50   You made 7 cozonacs! Now you have 16 eggs and 2.45BGN left.
  40. 1.25
  41.  
  42. Comments:
  43. We start by calculating the price for a pack of eggs, which is 75% of the price for 1 kg floor,
  44. which in this case is 1.25. The pack of eggs price is 0.9375.
  45. The price for 1l milk is 25% more than the price for 1kg floor and in this case it is – 1.5625,
  46. but we need the price for 0.250ml, which is - 0.390625. The total price for one cozonac is:
  47. 1.25 + 0.9375 + 0.390625 = 2.578125.
  48. And we start subtracting the price for a single cozonac from the budget,
  49. and for every cozonac we receive 3 eggs. So after the first subtraction we will have 17.921875 budget,
  50. 1 cozonac and 3 eggs. After the second - 15.34375 budget, 6 eggs,
  51. and on the third - 12.765625 budget and 9 eggs and since it’s the third,
  52. we need to subtract the lost eggs, which will be 3 – 2 = 1, so we subtract 1 from 9 and our eggs become 8.
  53. We continue subtracting money from the budget until the money aren't enough for us to make a cozonac.
  54. In the end we have 2.45BGN left.
  55. Input:
  56. 15.75
  57. 1.4
  58. Output:
  59. You made 5 cozonacs! Now you have 14 eggs and 1.31BGN left.
  60. """
  61. budget = float(input())
  62. price_1kg_flour = float(input())
  63. price_1_pack_eggs = price_1kg_flour * 0.75
  64. price_250_ml_milk = (price_1kg_flour * 1.25) / 4
  65.  
  66. count_colored_eggs = 0
  67. count_cozonacs = 0
  68.  
  69. while True:
  70.     price = price_1kg_flour + price_1_pack_eggs + price_250_ml_milk
  71.  
  72.     if budget - price < 0:
  73.         print(f"You made {count_cozonacs} cozonacs! Now you have {count_colored_eggs} eggs and {budget:.2f}BGN left.")
  74.         break
  75.  
  76.     budget -= price
  77.     count_cozonacs += 1
  78.  
  79.     count_colored_eggs += 3
  80.     if count_cozonacs % 3 == 0:
  81.         lost_eggs = count_cozonacs - 2
  82.         count_colored_eggs -= lost_eggs
Advertisement
Add Comment
Please, Sign In to add comment