Menu
CoddyTech

Suites Instead of end

Lesson 5 of 48 in Coddy's Python for Luau Developers course.

Luau uses keywords such as then and end to delimit control blocks. Python instead uses a colon followed by an indented suite, conventionally four spaces. Dedenting ends the suite. A Luau local declared inside a block has block scope; a Python assignment inside an if belongs to its surrounding function or module and only exists after that branch executes. Indentation therefore changes program behavior rather than serving as decoration.

Luau example

local stock = 7
if stock > 5 then
    print("bulk")
end
print("done")

Python

stock = 7
if stock > 5:
    print("bulk")
print("done")

Porting trap

Python has no end keyword to rescue misplaced indentation. A dedented print runs outside the conditional.

Implement the specified API in the editable Python files. The locked driver.py runs the program and supplies input/output. Keep its imports and names unchanged.

challenge icon

Challenge

Beginner

Read a nonnegative integer stock level. Print audit first. If stock is greater than 5, print bulk and then the stock number. Always print done last. Repair the block layout and add the missing output; no other lines should appear.

Print only the requested output, with a newline after each line. The supplied input lines read the test data; keep them and add your work below.

Your code goes in main.py. The locked driver.py starts your program and cannot be edited.

Try it yourself

# Starts the program in main.py. Edit main.py to solve the challenge.
from runpy import run_module

run_module("main", run_name="__main__")
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Python for Luau Developers

Practice on your own: Online Python compiler