Мой профиль
ACTIVITY 50 / 50

Final project: station controller

Try as many times as you need

Let’s understand

Build a program from familiar parts. A Station class holds one object’s energy. Its build(cost) method checks whether a construction is affordable. If so, it subtracts the cost and returns BUILT; otherwise it changes nothing and returns WAIT. A negative cost also returns WAIT. Separating the decision from input lets another game reuse the method.

Listen to the explanation

Example

# Break the project into three parts:
# 1. Store energy in an object.
# 2. Make one build decision.
# 3. Read and process all requests.
YOUR MISSION

Create Station with __init__(self, energy) and build(self, cost). Read starting energy, a request count n, then n integer costs. Print BUILT or WAIT for each request, then the remaining energy. Allow a build when cost >= 0 and cost <= self.energy.

I need a hint

Test the class with one build, then add the loop. Update self.energy inside the method, not a separate local variable. Test zero cost, insufficient energy and several builds in a row.

How to find an error
  1. Read the last line of the error message.
  2. Find the indicated line. Check quotes, parentheses and indentation.
  3. Change one thing and run again.

main.py

4 spaces

Your draft stays in this browser.

Result

Python
Your program’s output will appear here. Click Run.