Skip to main content
deleted 5 characters in body
Source Link
Caridorc
  • 27.6k
  • 7
  • 54
  • 135
Simply `right_pad  = makeSpace(1)`, not the long winded expression that always evaluated to one.

Simply right_pad = makeSpace(1), not the long winded expression that always evaluated to one.

Simply `right_pad  = makeSpace(1)`, not the long winded expression that always evaluated to one.

Simply right_pad = makeSpace(1), not the long winded expression that always evaluated to one.

simple
Source Link
Caridorc
  • 27.6k
  • 7
  • 54
  • 135

and

for x in range(staircase_height - 1):
    render(staircase_height - x, 0)
render(staircase_height - (x + 1), staircase_height - 1)

Use less variables

print(makeSpace(staircase_height + 1) + ("*" * 7))

Further simplify render

Simply `right_pad  = makeSpace(1)`, not the long winded expression that always evaluated to one.

Use less variables

print(makeSpace(staircase_height + 1) + ("*" * 7))

and

for x in range(staircase_height - 1):
    render(staircase_height - x, 0)
render(staircase_height - (x + 1), staircase_height - 1)

Use less variables

print(makeSpace(staircase_height + 1) + ("*" * 7))

Further simplify render

Simply `right_pad  = makeSpace(1)`, not the long winded expression that always evaluated to one.
less vars
Source Link
Caridorc
  • 27.6k
  • 7
  • 54
  • 135

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))

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))
names
Source Link
Caridorc
  • 27.6k
  • 7
  • 54
  • 135
Loading
more functions
Source Link
Caridorc
  • 27.6k
  • 7
  • 54
  • 135
Loading
Source Link
Caridorc
  • 27.6k
  • 7
  • 54
  • 135
Loading