[Python] How to make a triangle of x's in python?

Discussão em 'Python' iniciado por Stack, Fevereiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    How would I write a function that produces a triangle like this:

    x
    xx
    xxx
    xxxx
    xxxxx


    Let's say the function is def triangle(n), the bottom row would have n amount of x's

    All I know how to do is make a box:

    n = 5
    for k in range(n):
    for j in range(n):
    print('x', end='')
    print()

    Continue reading...

Compartilhe esta Página