Home > other >  In python how do you write a program that collects the radius of a circle and determines its area
In python how do you write a program that collects the radius of a circle and determines its area

Time:03-21

In python how do you write a program that collects the radius of a circle and determines its area. Then displays the radius and area (correct to two decimal places)

CodePudding user response:

If you mean to take the radius of a circle as a function argument and print the area to a console, you can do something like this.

import math

def circle_area(radius):
    print(round(radius * radius * math.pi), 2)

CodePudding user response:

expanding on shawntor's answer by adding user input ability:

import math

def circle_area(radius):
    return round(radius * radius * math.pi, 2)

user_input = input("input the radius of your circle:")
print(circle_area(int(user_input)))
  • Related