Nikolay9

15.bread_factory

Feb 2nd, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. energy = 100
  2. coins = 100
  3. events = input().split("|")
  4. fail = 0
  5. energy1 = 0
  6.  
  7. for idx in events:
  8.     command = idx.split("-")
  9.     action = command[0]
  10.     value = int(command[1])
  11.  
  12.     if action == "rest":
  13.         energy1 = energy
  14.         energy += value
  15.         if energy > 100 and energy1 < 100:
  16.             print(f"You gained {energy - 100} energy.\n"
  17.                   f"Current energy: 100.")
  18.             energy = 100
  19.         elif energy1 == 100:
  20.             print("You gained 0 energy.\n"
  21.                   "Current energy: 100.")
  22.             energy = 100
  23.         else:
  24.             print(f"You gained {value} energy.\n"
  25.                   f"Current energy: {energy}.")
  26.  
  27.     elif action == "order":
  28.         if energy <= 30:
  29.             energy += 50
  30.             print("You had to rest!")
  31.             fail += 1
  32.             continue
  33.         else:
  34.             coins += value
  35.             print(f"You earned {value} coins.")
  36.         energy -= 30
  37.  
  38.     else:
  39.         if coins >= value:
  40.             coins -= value
  41.             print(f"You bought {action}.")
  42.         else:
  43.             fail += 1
  44.             print(f"Closed! Cannot afford {action}.")
  45.             break
  46.  
  47. if fail == 0:
  48.     print(f"Day completed!\n"
  49.           f"Coins: {coins}\n"
  50.           f"Energy: {energy}")
  51.  
Advertisement
Add Comment
Please, Sign In to add comment