To write a Python program that calculates the area of a circle based on user input, you can use the following code:

```
import math
# Get the radius from the user
radius = float(input("Enter the radius of the circle: "))
# Calculate the area
area = math.pi * radius**2
# Print the result
print(f"The area of the circle is: {area}")
```

In the code above:

- The
`math`

module is imported to access the value of pi (`math.pi`

) and perform mathematical operations. - The
`input()`

function is used to prompt the user to enter the radius of the circle. The`float()`

function is used to convert the user’s input into a floating-point number. - The area of the circle is calculated using the formula
`math.pi * radius**2`

. - The result is printed to the console using the
`print()`

function. The`f-string`

formatting is used to display the area value within the string.

When you run the program, it will prompt you to enter the radius of the circle. After you provide the input, it will calculate and display the area of the circle.

Note that the radius should be a positive number. You may want to consider adding input validation or error handling to ensure that the user enters a valid radius.

## + There are no comments

Add yours