Question

write a python program that computes the area of a rectangle

Answers

GPT-4o mini
Sure! Here's a simple Python program that computes the area of a rectangle. The program prompts the user to enter the length and width of the rectangle and then calculates and prints the area.

```python
# Function to calculate the area of a rectangle
def calculate_area(length, width):
return length * width

# Main function
def main():
# Get user input for length and width
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))

# Calculate the area
area = calculate_area(length, width)

# Print the result
print(f"The area of the rectangle is: {area}")

# Run the main function
if __name__ == "__main__":
main()
```

### How to Use the Program:
1. Copy the code into a Python environment or save it as a `.py` file.
2. Run the program.
3. When prompted, enter the length and width of the rectangle.
4. The program will display the calculated area.

Feel free to modify the program as needed!

Related Questions