In this exercise, we modify our code from exercise 2 to prompt a user to enter the dimensions for the length and the width of our rectangle.
You can compare your code to ours
below:
print('*'
* 60)
print('A PROGRAM TO CALCULATE THE AREA
AND PERIMETER OF A RECTANGLE')
print('*' * 60)
print()
length =
float(input('Enter the length of the rectangle: '))
width =
float(input('Enter the width of the rectangle: '))
area = length * width
perimeter = 2*(length
+ width)
print()
print('Length is
',length,'cm')
print('width is
',width,'cm')
print('=' * 25)
print('Area is
',area,'sq. cm')
print('=' * 25)
print('Perimter is
',perimeter,'cm')
print('-' * 25)
print('Thank you')
print(f'Area is {area}
sq. cm and Perimeter is {perimeter} cm')
in the updated code above, I used the
float option on the received inputs so as to account for floating-point inputs
from the users.
I included a few print() lines so there
would be some spacing in the output.
I added the print(‘*’ * 60) line above
and below the title to so as to print the string, *, 60 times on the line.
I did a similar thing with the print(’=’ * 25) and the print(‘-‘ * 25).
Lastly, I used the f’ format to give a
second option for printing the output.
No comments:
Post a Comment