SimeonTs

SUPyF2 Lists Basics Exercise - 10. Bread Factory

Oct 3rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.46 KB | None | 0 0
  1. """
  2. Lists Basics - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1725#9
  4.  
  5. SUPyF2 Lists Basics Exercise - 10. Bread Factory (not included in final score)
  6.  
  7. Problem:
  8. As a young baker, you are baking the bread out of the bakery.
  9. You have initial energy 100 and initial coins 100. You will be given a string,
  10. representing the working day events. Each event is separated with '|' (vertical bar): "event1|event2|event3…"
  11. Each event contains event name or item and a number, separated by dash("{event/ingredient}-{number}")
  12. • If the event is "rest": you gain energy, the number in the second part.
  13. But your energy cannot exceed your initial energy (100). Print: "You gained {0} energy.".
  14. After that, print your current energy: "Current energy: {0}.".
  15. • If the event is "order": You've earned some coins, the number in the second part.
  16. Each time you get an order, your energy decreases with 30 points.
  17. o   If you have energy to complete the order, print: "You earned {0} coins.".
  18. o   If your energy drops below 0, you skip the order and gain 50 energy points. Print: "You had to rest!".
  19. • In any other case you are having an ingredient, you have to buy.
  20. The second part of the event, contains the coins you have to spent and remove from your coins.
  21. o   If you are not bankrupt (coins <= 0) you've bought the ingredient successfully,
  22. and you should print ("You bought {ingredient}.")
  23. o   If you went bankrupt, print "Closed! Cannot afford {ingredient}." and your bakery rush is over.
  24. If you managed to handle all events through the day, print on the next three lines:
  25. "Day completed!", "Coins: {coins}", "Energy: {energy}".
  26. Input / Constraints
  27. You receive a string, representing the working day events, separated with '|' (vertical bar): " event1|event2|event3…".
  28. Each event contains event name or ingredient and a number, separated by dash("{event/ingredient}-{number}")
  29. Output
  30. Print the corresponding messages, described above.
  31.  
  32. Examples:
  33. Input:
  34. rest-2|order-10|eggs-100|rest-10
  35.  
  36. Output:
  37. You gained 0 energy.
  38. Current energy: 100.
  39. You earned 10 coins.
  40. You bought eggs.
  41. You gained 10 energy.
  42. Current energy: 80.
  43. Day completed!
  44. Coins: 10
  45. Energy: 80
  46.  
  47. Input:
  48. order-10|order-10|order-10|flour-100|order-100|oven-100|order-1000
  49.  
  50. Output:
  51. You earned 10 coins.
  52. You earned 10 coins.
  53. You earned 10 coins.
  54. You bought flour.
  55. You had to rest!
  56. Closed! Cannot afford oven.
  57. """
  58. energy = 100
  59. coins = 100
  60. events = input().split("|")
  61.  
  62. day_finished = True
  63.  
  64. for event in events:
  65.     info = event.split("-")
  66.     event_or_ingredient = info[0]
  67.     number = int(info[1])
  68.  
  69.     if event_or_ingredient == "rest":
  70.         if (number + energy) > 100:
  71.             more_energy = (energy + number) - 100
  72.             number -= more_energy
  73.         energy += number
  74.         print(f"You gained {number} energy.")
  75.         print(f"Current energy: {energy}.")
  76.     elif event_or_ingredient == "order":
  77.         if energy >= 30:
  78.             energy -= 30
  79.             coins += number
  80.             print(f"You earned {number} coins.")
  81.         else:
  82.             energy += 50
  83.             print("You had to rest!")
  84.     else:
  85.         if coins - number > 0:
  86.             coins -= number
  87.             print(f"You bought {event_or_ingredient}.")
  88.         else:
  89.             day_finished = False
  90.             print(f"Closed! Cannot afford {event_or_ingredient}.")
  91.             break
  92.  
  93. if day_finished:
  94.     print("Day completed!")
  95.     print(f"Coins: {coins}")
  96.     print(f"Energy: {energy}")
Add Comment
Please, Sign In to add comment