Drawing a hollow asterisk square

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

    Heres my example:

    print("Enter width")
    width = int(input())
    print("Enter height")
    height = int(input())
    
    for i in range(height):
        if i in[0]:
            print("* "*(width))
        elif i in[(height-1)]:
            print("* "*(width))
        else:
            print("*"+"  "*(width-2)+" *")
    
    input()
    

    Output: Image link

    Hope this helps everyone else, who wants to leave spaces between asteriks, while printing a rectangle and if there are any mistakes in my code let me know, because I'm a beginner myself.

提交回复
热议问题