[Python] Hollow Inverted Half Pyramid

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

  1. Stack

    Stack Membro Participativo

    I have to print a hollow inverted pyramid:

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


    Following is my code:

    n = int(input())

    for i in range(n,0,-1):
    if i == n:
    print(n*'*', end = '')
    if i > 1 and i <n:
    print('*'+(i-2)*' '+'*')
    else:
    print('*')
    print()


    For input as 6 I am not sure why my code is printing 7 stars. If anyone could help explain what I am doing wrong or missing would be really great!

    Continue reading...

Compartilhe esta Página