Write a function that:

(i) Asks the user to input a diameter of circle in inches.

(ii) Sets a variable called radius to one half of that number.

(iii) Calculate the area of circle.

(iv) Print the area of circle with appropriate unit.

(v) Return this same amount as the output of the function.

 

Answer:

import math

def circle_area ():

    d=float(input( "Enter the diameter of the circle in inches: " ))

    r=d/ 2

    area=(math.pi)*(r** 2 )

    print( "Area of a circle with diameter " ,d, " inches is " ,area, " sq inches" )

    return (area)

Question 21-Write a function that Teachoo.JPG

Go Ad-free

Transcript

Question 21 Write a function that: (i) Asks the user to input a diameter of circle in inches. (ii) Sets a variable called radius to one half of that number. (iii) Calculate the area of circle. (iv) Print the area of circle with appropriate unit. (v) Return this same amount as the output of the function. Importing the ‘math’ library Accepting a user input for diameter and assigning it to the variable ‘d’ Calculating area and assigning it to the variable ‘area’ Invoking function ‘circle_area’ defining a function ‘circle_area’ to calculate the area Dividing the diameter by 2 and assigning it to ‘r’ output

Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo