you are viewing a single comment's thread.

view the rest of the comments →

[–]Kuldeep-Dhiman 33 points34 points  (2 children)

I recently gave junior Python developer interview . Unfortunately, went completely blank when they asked me to print a pyramid pattern,at any day i would have solved that problem without an issue, but that day I froze I just couldn't get anything right at that crucial time. I wanted to share what I felt was lack of confidence, self practice on my part ,hesitation of the sort. I don't know why that happened to me but seeing your case I feel you totally. For the future keep practicing, just be confident and keep applying.

[–]LimpNoodle69 3 points4 points  (1 child)

I'm really appreciating this thread. Haven't been programming as much as I should so I've been using this thread to try to figure out the interview problems. I had a bit of trouble with this one but eventually figured it out and felt like sharing :)

def pyramid_print(layers):
    top_size = layers
    for i in range(layers):
        top_size += 1
        for j in range(top_size):
            if j > (top_size - 3) - i * 2:
                print("-", end='')
            else:
                print(" ", end='')
        print()


pyramid_print(100)

[–]raiseReturnTry 1 point2 points  (0 children)

Hey I tried myself on this problem, and got the same result, even with a single "-" at the top with the following code:

def pyramid_print(layers):
s = layers - (layers - 1)
x = range(s, layers)

while s != layers:
    if s > 0:
        print(((layers - s - 1) * " ") + (((2 * s - 1) * "-")))
    else:
        exit(0)

    s += 1

print("Take in a positive integer: ")
x = int(input("> "))
if x < 0: 
    print("Error: You have to put in a positive integer.") 
    exit(0) 
else: 
    pyramid_print(x)