In: Computer Science
Write a Python program that takes as input two numbers, the height, and width of a rectangle. It then prints a rectangle with height lines and width characters in each line. The rectangle should contain information regarding its dimensions and area inside (centered vertically but not horizontally). If any part of the information (including two stars on each end and a space before and after the line) does not fit in the rectangle, then print the complete information after the rectangle.
Please find the code below::
width = int(input('Enter width of the rectangle : '))
height = int(input('Enter height of the rectangle : '))
str1 = 'Width : '+str(width)+' Height : '+str(height)+' Area :
'+str(width*height)
print()
for i in range(height):
printed = False
for j in range(width):
if (i==0 or j==0 or j==(width-1) or i==(height-1)) and not
printed:
print("*",end='')
elif(i==height//2 and not printed):
if(len(str1)<=(width-2)):
print(str1,end='')
for k in range(width-2-len(str1)):
print(" ",end='')
print("*",end='')
printed = True
else:
print(" ",end='')
elif not printed:
print(" ",end='')
if(i==height//2 and not printed):
print(str1,end='')
print()