Write a Python program that calculates the area of a circle based on the radius entered by the user.

Program

from math import pi
def myfun():
    r = float(input("Input the radius of the circle : "))
    # Calculate the area of the circle using the formula: area = π * r^2
    area = pi * r ** 2
    print("The area of the circle with radius " + str(r) + " is: " + str(area))
      
if __name__=="__main__":      
    myfun()

Output:

Input the radius of the circle : 1
The area of the circle with radius 1.0 is: 3.141592653589793

Input the radius of the circle : 4
The area of the circle with radius 4.0 is: 50.26548245743669

For latest job updates join Telegram Channel: https://t.me/sateeshm

Programs