Skip to main content
Tweeted twitter.com/StackCodeReview/status/656290294510571521
edited tags
Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
Removed tags from title. Improved readability.
Source Link
Mast
  • 13.5k
  • 12
  • 54
  • 119

Python 2.7: Printing a staircase of text. Beginner

So basically, a user is prompted to input a number of stairs and a staircase when a guy on it is generated. I know this is sloppy and my variable names are rough, I'm actively working to change them now. I thought I would go ahead and post the working code though. 

How can I improve on this? What can I do better to do more with less. Thanks. PSA?

Note: I'm very new to Python and general programming. Code:

Python 2.7: Printing a staircase of text. Beginner

So basically, a user is prompted to input a number of stairs and a staircase when a guy on it is generated. I know this is sloppy and my variable names are rough, I'm actively working to change them now. I thought I would go ahead and post the working code though. How can I improve on this? What can I do better to do more with less. Thanks. PSA: I'm very new to Python and general programming. Code:

Printing a staircase of text

So basically, a user is prompted to input a number of stairs and a staircase when a guy on it is generated. I know this is sloppy and my variable names are rough, I'm actively working to change them now. I thought I would go ahead and post the working code though. 

How can I improve on this? What can I do better to do more with less?

Note: I'm very new to Python and general programming.

Source Link
Aaron
  • 347
  • 1
  • 4
  • 11

Python 2.7: Printing a staircase of text. Beginner

So basically, a user is prompted to input a number of stairs and a staircase when a guy on it is generated. I know this is sloppy and my variable names are rough, I'm actively working to change them now. I thought I would go ahead and post the working code though. How can I improve on this? What can I do better to do more with less. Thanks. PSA: I'm very new to Python and general programming. Code:

def render(num, num3):
    num2 = num - 1
    white_space7 = ""
    
    white_space = ""
    for x in range(num):
        white_space = white_space + "       "
    c = num
    white_space5 = makeSpace(Num - num2)
    if num3 != 0:
        white_space7 = makeFloor(num3)
        print(white_space + "      *" + white_space5 + "*")
        print(white_space + "   o  *" + white_space5 + "*")
        print(white_space + "  /|\ *" + white_space5 + "*")
        print(white_space + "  / \ *" + white_space5 + "*")
        print(white_space + "*******" + white_space7 + "*")
    else:
        print(white_space + "      *" + white_space5 + "*")
        print(white_space + "   o  *" + white_space5 + "*")
        print(white_space + "  /|\ *" + white_space5 + "*")
        print(white_space + "  / \ *" + white_space5 + "*")
        print(white_space + "*******" + white_space7 + white_space5 + "*")

def makeSpace(num):
    white_space4 = ""
    for x in range(num):
        white_space4 = white_space4 + "       "
    return white_space4

def makeFloor(num):
    white_space6 = ""
    num4 = num + 1
    for x in range(num4):
        white_space6 = white_space6 + "*******"
    return white_space6
    
    

Num = raw_input("Number of Stairs:" )
Num = int(Num)

white_space2 = ""
for x in range(Num + 1):
    white_space2 = white_space2 + "       "
print(white_space2 + "*******")
y = Num

white_space2 = ""


for x in range(Num):
    if (x < Num - 1):
        render(y,0)
        y -= 1
    else:
        render(y,Num - 1)
        y -= 1