Advertisement
Guest User

Untitled

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