Exercise
Enhanced Rectangle V3
Objective
Develop a Python program to prompt the user for their name and a size, and display a hollow rectangle with it:
Enter your name: Yo
Enter size: 4
YoYoYoYo
Yo Yo
Yo Yo
YoYoYoYo
(Note: The underscores _ should not be displayed on screen; your program should display blank spaces inside the rectangle)
Example Python Exercise
Show Python Code
# Prompt the user for their name and the size of the rectangle
name = input("Enter your name: ")
size = int(input("Enter size: "))
# Print the top row of the rectangle
print(name * size)
# Print the middle rows with spaces inside
for i in range(size - 2):
print(name + ' ' * (len(name) * (size - 2)) + name)
# Print the bottom row of the rectangle
if size > 1:
print(name * size)
Output
Enter your name: Yo
Enter size: 4
YoYoYoYo
Yo Yo
Yo Yo
YoYoYoYo
Share this Python Exercise