 Loading... Pavel32 0 Точки

## Fundamentals Module - List Basics Exercise - 10. Bread Factory: 50/100 need help

```events = input().split("|")
energy = 100
coins = 100
is_fine = True
for c in events:
state, amount = c.split("-")
amount = int(amount)
if state == "rest":
if energy + amount > 100:
gained = 100 - energy
else:
gained = amount
energy += gained
print(f'You gained {gained} energy.')
print(f'Current energy: {energy}.')
elif state == "order":
energy -= 30
if energy > 0:
coins += amount
print(f'You earned {amount} coins.')
else:
energy = 0
energy += 50
print("You had to rest!")
else:
coins -= amount
if coins > 0:
print(f"You bought {state}.")
else:
print(f'Closed! Cannot afford {state}.')
is_fine = False
break
if is_fine:
print(f'Day completed!')
print(f"Coins: {coins}")
print(f'Energy: {energy}')```
Тагове:
0 MartinBG 3828 Точки

Проблемите са при команда order.

Заменете:

``````    elif state == "order":
energy -= 30
if energy > 0:
coins += amount
print(f'You earned {amount} coins.')
else:
energy = 0
energy += 50
print("You had to rest!")``````

С:

``````    elif state == "order":
energy -= 30
if energy >= 0: # >=
coins += amount
print(f'You earned {amount} coins.')
else:
energy += 30 + 50 # restore used energy(30) + 50
print("You had to rest!")``````

0