mercredi 3 octobre 2018

No output when using nested for loops inside if statements

I'm trying to print out a series of patterns based off of the user input. However, when I add an if statement or while loop to it, I get no output even if I selected the correct number. The patterns work if I don't add the loops to it. I'm new to python and don't understand why it isn't printing anything out.

num_draw = input("Please enter the number of the design you would like[1-6] or -1 to quit: ")

#while num_draw != -1:
if num_draw == 1:

    for i in range(0, 5):
        for j in range(0, i+1):
            print("* ",end="")
        print()
elif num_draw == 2:
#2
    size = 5
    isize = size - 2
    print ('*' * size)
    for i in range(isize):
        print ('*' + ' ' * isize + '*')
    print ('*' * size)

elif num_draw == 3:

    for i in range(5):
        for j in range(5):
            print(" *"[(j + i + 1)%2], end=' ')
        print()
elif num_draw == 4:

    for i in range(0, 5):
        for j in range(0, i+1):
            print("* ",end="")
        print()


elif num_draw == 5:
    for i in range(0, 5):
        for j in range(5, i, -1):
            print("@ ", end="")
        print()


elif num_draw == 6:
    k = 8
    for i in range(0, 5):
        for j in range(0, k):
            print(end=" ")
        k = k - 2
        for j in range(0, i+1):
            print("* ", end="")
        print()

Aucun commentaire:

Enregistrer un commentaire