Calculate rectangle area with user input

Report a typo

Write a Python program that calculates the area of a rectangle. Your program should define a function called `calculate_area` that accepts the length and width of the rectangle as parameters. The function should return the calculated area. In the main program, prompt the user to enter the length and width of the rectangle, call the `calculate_area` function, and print the result.

Sample Input 1:

5
3

Sample Output 1:

15.0

Sample Input 2:

2.5
4

Sample Output 2:

10.0
Write a program in Python 3
# Import necessary libraries

# Function to calculate the area of a rectangle
def calculate_area(length, width):
# Your code here


# Main program
def main():
length = float(input())
width = float(input())

area = calculate_area(length, width)
print(area)

if __name__ == "__main__":
main()
___

Create a free account to access the full topic