Drawing a hollow asterisk square

前端 未结 10 1616
情话喂你
情话喂你 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:32

    size = int(input('Enter the size of square you want to print = '))
    for i in range(size):           # This defines the rows
        for j in range(size):       # This defines the columns
            print('*' , end=' ')    # Printing * and " end=' ' " is giving space      after every * preventing from changing line
        print()                     # Giving a command to change row after every column in a row is done
    
    print()                         # Leaving one line
    for k in range(size):           # This defines the rows
        print('* ' *size)           # Defines how many times * should be multiplied
    

提交回复
热议问题