1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to create overlapping diamonds

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024 às 10:52.

  1. Stack

    Stack Membro Participativo

    my task is to create n diamonds with height 2n-1 and b as blocks, that are overlapping in the middle like this. The overlapping point means that diamonds share blocks at the middle level.

    [​IMG]

    so my current output looks like this

    [​IMG]

    this is my code

    def draw_diamonds(n, b):
    height = 2 * n - 1
    diamonds = []

    for i in range(height):
    line = ""
    for j in range(n):
    if i < n:
    if j == 0:
    line += " " * (n - i - 1) + b * (2 * i + 1)
    else:
    line += " " * (n - i) + b * (2 * i + 1) + ""
    else:
    if j == 0:
    line += " " * (i - n + 1) + b * (2 * (height - i) - 1)
    else:
    line += " " * (i - n + 1) + b * (2 * (height - i) - 1) + " "
    diamonds.append(line)

    for line in diamonds:
    print(line)

    n, b = map(str, input().split())
    draw_diamonds(int(n), b)

    Continue reading...

Compartilhe esta Página