Using Python:
Write a program which includes functions to calculate the area, perimeter and diameter of a circle. You should have a functions compute_area(), compute_perimeter() and compute_diameter(). In addition, you should have a main() function. Your main function should ask the user for the radius of a circle, then ask the user if they would like to compute the area, the perimeter or the diameter. The user should enter "A" for area, "P" for perimeter and "D" for diameter. Your prompt should let the user know which to choose - and you should allow both upper- and lower-case letters for entry. Your main function should then call the appropriate function, passing in the radius. All compute functions should return the value which is computed. Your main function should then print out the area, perimeter or diameter, based on the user's choice.
import math
#computes and returns area
def compute_area(r):
return math.pi* r * r
def compute_perimeter(r):
return 2 * math.pi* r;
def compute_diameter(r):
return 2 * r
if __name__ == '__main__':
#readin radius
r=float(input("Enter radius of circle: "))
#reading choice
ch=input("A Area P Perimeter D Diameter")
#calling functions based on choice
if(ch=='A' or ch=='a'):
print("Area : ",compute_area(r))
if(ch=='P' or ch=='p'):
print("Perimeter : ",compute_perimeter(r))
if(ch=='D' or ch=='d'):
print("Diameter : ",compute_diameter(r))
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Get Answers For Free
Most questions answered within 1 hours.