57.4k views
1 vote
Codehs 7.4.6: Gymnastics Mats

Calculate how many mats will be needed to fill a room given the dimensions of each mat and the dimensions of the room.

In the start function, ask the user for the dimensions of the mat. Calculate the area and return that value to the start function. Print the area of the mat to the user. Then ask the user for the dimensions of the room and calculate how many mats will be needed to fill the room. Print this value to the user.

You will need to use a function named calculateArea in your program. This function should take two parameters (length and width).

1 Answer

2 votes

Below is a simple Python program that follows the specifications.

def calculateArea(length, width):

area = length * width

return area

def start():

# Get dimensions of the mat from the user

mat_length = float(input("Enter the length of the mat: "))

mat_width = float(input("Enter the width of the mat: "))

# Calculate and print the area of the mat

mat_area = calculateArea(mat_length, mat_width)

print(f"The area of the mat is: {mat_area} square units")

# Get dimensions of the room from the user

room_length = float(input("Enter the length of the room: "))

room_width = float(input("Enter the width of the room: "))

# Calculate the number of mats needed to fill the room

mats_needed = (room_length * room_width) / mat_area

# Print the result

print(f"You will need {int(mats_needed)} mats to fill the room.")

# Call the start function to begin the program

start()

User Stevec
by
3.6k points