Drawing a hollow asterisk square

前端 未结 10 1621
情话喂你
情话喂你 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条回答
  •  抹茶落季
    2020-12-09 14:36

    You can print out a single '*', followed by size-2 spaces, then a single '*'. This will give you the "hollow" portion. The first and last lines need the full length:

    size = 5
    inner_size = size - 2
    print ('*' * size)
    for i in range(inner_size):
        print ('*' + ' ' * inner_size + '*')
    print ('*' * size)
    

提交回复
热议问题