ACTIVITY 24 / 50
Try as many times as you needProject: robot route
Let’s understand
Combine input, a loop and conditions. A robot receives an energy amount followed by three commands. MOVE uses two units if enough energy remains. Any other command leaves the amount unchanged. Report the remaining energy after each command. Process all three commands in order, even if energy runs out.
Listen to the explanation
Example
for turn in range(2):
command = input()
if command == "LOOK":
print("Looking")Read integer energy. Then read three commands. For MOVE with energy >= 2, subtract 2. Print energy after each command.
I need a hint
Use for with range(3). Read a command, check both conditions with and, then print the remaining energy.
How to find an error
- Read the last line of the error message.
- Find the indicated line. Check quotes, parentheses and indentation.
- Change one thing and run again.
main.py
4 spaces
Your draft stays in this browser.
Result
PythonYour program’s output will appear here. Click Run.
Мой профиль