1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Printing diamond Pattern in python [closed]

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    I have to print a diamond pattern in Python, but the diamond is different. There are 2 input variables m and n. m represent the number of the blocks where n represents the head on that block, and if the lines on the head are greater than 2, then lines () are inside the block [Head_lines - 2 = number of '']. check the attached picture for reference

    [​IMG]

    def picture(rows, columns):
    for _ in range(rows):
    # Top part
    print((' ' + '/\\' * columns).rstrip())
    # Middle part
    print((' ' + '/ \\' * columns).rstrip())
    print((' ' + '\\ /' * columns).rstrip())
    # Bottom part
    print((' ' + '\\/' * columns).rstrip())

    if rows > 1:
    print((' ' + '/ \\' * columns).rstrip())
    print((' ' + '\\ /' * columns).rstrip())
    print((' ' + '\\/' * columns).rstrip())
    picture(1,1)
    picture(3,4)


    This is code I wrote, and I still haven't figured out a way to add '_' in the code.

    Continue reading...

Compartilhe esta Página