jeudi 29 septembre 2022

Why my code does not produce the pattern in the 2nd loop? (Python)

Language: Python Why my codes not work in the 2nd iteration? I'd like to understand what I'm doing wrong? I want to give input in row = 3 or 5 or x, and then I expect it to produce the following output pattern:

#When row = 3

1|. . #
2|. ##
3|###

Please note that the number of "." will be opposite to the number of "#" *i loop prints a new line, j loop prints "#", and k loop prints "."

''' row = 3

for i in range(1, row + 1):
    for j in range(1, i + 1):
        for k in range(1, (row - i) + 1):
            print(".", end= "")
        print("#", end="")
    print("")

'''

Aucun commentaire:

Enregistrer un commentaire