[Python] Printing a star shape using loops in python

Discussão em 'Python' iniciado por Stack, Maio 15, 2025.

  1. Stack

    Stack Membro Participativo

    I was trying to write a python code that would print a star shape using loops but I just can't get the shape right. Please suggest some corrections.

    This is my terminal: [​IMG]

    This is my code:

    for i in range(1,11):
    if i == 1:
    print(' '*39 + '*')
    elif i == 10:
    print(" "*12 +'*'*19+ ' '*17 + '*'*19)
    else :
    print(' '*(4*10-i) + '*' + ' '*(2*i-3) + '*')
    for p in range(11,17):
    print(' '*(p*2-9)+'*'+(' '*(63-p) +"*"))


    It should a five pointed star but with asterisk:

    [​IMG]

    Continue reading...

Compartilhe esta Página