Objective
Develop a Python program that prompts the user for a symbol and a width, and displays a hollow square of that width using that symbol for the outer border, as shown in this example:
Enter a symbol: 4
Enter the desired width: 3
444
4 4
444
Example Python Exercise
Show Python Code
symbol = input("Enter a symbol: ")
width = int(input("Enter the desired width: "))
i = 0
while i < width:
if i == 0 or i == width - 1:
print(symbol * width)
else:
print(symbol + " " * (width - 2) + symbol)
i += 1
Output
Enter a symbol: 4
Enter the desired width: 3
444
4 4
444
Share this Python Exercise