[Python] How to print a right aligned triangle with nested for loops (no string addition or...

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    This code kind of works but it keeps on giving me a pyramid instead of right aligned triangle. For example: I'm trying for something like this:

    *
    **
    ***
    ****
    *****

    Heres my code


    height = int(input("What is your height: "))

    count = 1
    space_count = height
    for rows in range (height):
    for spaces in range (space_count):
    print(end=' ')
    for stars in range (count):
    print ("*", end=' ')
    space_count = space_count - 1
    count = count + 1

    print()

    Continue reading...

Compartilhe esta Página