Making a hollow box in Python to these specifications?

前端 未结 5 954
盖世英雄少女心
盖世英雄少女心 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

    The code should be like:

    line =  "*"*(2*n)
    print line
    s  = "*" + " "*(n-2) + "*"
    for i in range(n-2):
        print s
    print line         
    

    The line:

    "*"*(2*n)
    

    specifies a string of "*", repeated 2*n times. You wanted 2*n column right.. This prints 2*n "*"

提交回复
热议问题