Drawing a hollow asterisk square

前端 未结 10 1643
情话喂你
情话喂你 2020-12-09 14:09

I\'m trying to figure out how to turn my whole square into a hollow one. The few things I\'ve tried so far haven\'t been very successful as I end up getting present

10条回答
  •  旧时难觅i
    2020-12-09 14:45

    Here is my python code for drawing a square by entered size N.

    n = int(input())
    print('*' * n)
    for i in range(n-2):
        print ('*' + ' ' * (n-2) + '*')
    print('*' * n)
    

    Basically the first and the last print('*' * n) are drawing the top and the bottom lines and the for cycle prints the body.

    Output example: N=3

    ***
    * *
    ***
    

    Output example: N=5

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

提交回复
热议问题