43.4k views
1 vote
A program is required to read from the screen the lenght and widht of a rectangular house block, and the lenght and width of the rectangular house that has been built on the block. The algorithm should then compute and display the mowing time required to cut the grass around the house, at the rate of two square metres per minute.

User Treddy
by
6.9k points

1 Answer

4 votes

Here's a Python program that will read the dimensions of the block and the house from the user, compute the area of the lawn, and then display the time it would take to mow the lawn at a rate of 2 square meters per minute:

# read the dimensions of the block

block_length = float(input("Enter the length of the block (in meters): "))

block_width = float(input("Enter the width of the block (in meters): "))

# read the dimensions of the house

house_length = float(input("Enter the length of the house (in meters): "))

house_width = float(input("Enter the width of the house (in meters): "))

# compute the area of the lawn

lawn_area = (block_length * block_width) - (house_length * house_width)

# compute the time to mow the lawn

mowing_time = lawn_area / 2

# display the result

print("The time required to mow the grass around the house is:", mowing_time, "minutes")

The program uses the input() function to read the dimensions of the block and the house from the user, and then uses the formulas (block_length * block_width) and (house_length * house_width) to compute the area of the block and the house, respectively. The program then subtracts the area of the house from the area of the block to get the area of the lawn.

Finally, the program uses the formula lawn_area / 2 to compute the time it would take to mow the lawn at a rate of 2 square meters per minute, and displays the result using the print() function.

User Borisvanax
by
9.0k points