Making a hollow box in Python to these specifications?

前端 未结 5 994
盖世英雄少女心
盖世英雄少女心 2021-01-28 06:26

I\'m to \"Write a python program that prompts the user to input a positive integer n. The program then prints a hollow rectangle with n rows and 2*n columns. For a example an in

5条回答
  •  星月不相逢
    2021-01-28 06:48

    def make_box():       
        size = int(input('Please enter a positive integer between 1 and 15: '))
        for i in range(size):
            if i == 0 or i == size - 1:
                print("*"*(size+2))
            else:
                print("*" + " "*size + "*")
    
    
    make_box()
    

    Output: (n=15)

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

提交回复
热议问题