Avoid reassigning the same variable
You re-assign white_space7
and that gave me headaches when refactoring, reassigning is generally avoided in Python.
Simplify branching
The printing part in render
:
print(white_space + " *" + white_space5 + "*")
print(white_space + " o *" + white_space5 + "*")
print(white_space + " /|\ *" + white_space5 + "*")
print(white_space + " / \ *" + white_space5 + "*")
if num3 != 0:
print(white_space + "*******" + white_space7 + "*")
else:
print(white_space + "*******" + white_space5 + "*")
Extract common code out of branches.
Use less variables
You can use a simple subtraction in the loop to easily avoid the y
variable:
for x in range(staircase_height):
if (x < staircase_height - 1):
render(staircase_height - x,0)
else:
render(staircase_height - x,staircase_height - 1)
and:
print(makeSpace(staircase_height + 1) + ("*" * 7))