Question

Using Python: Write a program which includes functions to calculate the area, perimeter and diameter of...

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.

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python program to calculate the area of a circle. The user needs to input...
Write a Python program to calculate the area of a circle. The user needs to input the value of the radius of the circle. area = 3.14 x radius x radius You should use a function named circlearea to perform the calculation 3. Write a Python program to calculate the area of a square. The user needs to input the value of the length of the square. area = len*len You should use a function named squarearea to perform the...
ALL IN PYTHON PLEASE Problem 4 Write a program to compute the area of a circle...
ALL IN PYTHON PLEASE Problem 4 Write a program to compute the area of a circle some 'n' times. You must accept n and r from the user. Area is calculated using (22/7.0)*r*r - where r is the radius. Implement using value-returning functions. Hint: create a function to calculate area taking r as a parameter. In the main() function, ask for n and create a loop where you input r and invoke the area function n times. Rubric: Correct use...
Listing 1 shows ABCD.cpp program to compute diameter, circumference and area for a circle with r,...
Listing 1 shows ABCD.cpp program to compute diameter, circumference and area for a circle with r, radius without user-defined function. Listing 2 shows the expected output of ABCD.cpp on the screen after creating user-defined functions for 3 circles of radius. Write a complete code to compute an output of 3 circles with r, radius as shown in Listing 2. Your answer should have four (4) functions as stated below as function declaration. double displayRadius(double); double displayDiameter(double); double displayCircumference(double); double displayArea(double);
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
In C programming, Thank you Write a program to compute the area of a circle. You...
In C programming, Thank you Write a program to compute the area of a circle. You have to write a complete “C” program that compiles and runs in Codeblocks. Program requirements: 1. Declare the variables needed: radius (r) and area (yourLastName). 2. Calculate and print the area of each circle. 3. The program MUST prompt the user for a new radius (r) over and over until the user types -1. 5. Use the type double for all decimal numbers. 6....
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
In Java The Circle. In one program, write 3 separate functions, and use them. Calculate area...
In Java The Circle. In one program, write 3 separate functions, and use them. Calculate area of circle, parameter radius. Use math lib ‘pow’ function to help with calc: calcArea Calculate diameter of circle, parameter radius: calcDiameter Calculate circumference of circle, parameter radius:calcCircumference Test radius sizes: 5, 42, 12.30
The last thing we will learn about in python is functions. Functions are a great way...
The last thing we will learn about in python is functions. Functions are a great way to organize your program - we use them to write code that is executed only under certain circumstances - for instance when you're using Amazon, any of the following are likely functions within their program: - Add item to cart, determine arrival date,  create a new address, compute taxes, compute shipping charges, charge credit card Because you can write a task-specific function once, and ensure...
By using Python code answer the following parts: A) Write a program to ask the user...
By using Python code answer the following parts: A) Write a program to ask the user to input their name and then output the type and length of the input. B) Write a program to output the last 11 letters of 'Introduction to Indiana'. C) Write a program to output the 3rd to the 11th letters of 'Introduction to Indiana'. D) Write a program to ask the user to input a float number and output the rounded value of it...
Complete the program to calculate and print the circumference and area of a circle, rounded to...
Complete the program to calculate and print the circumference and area of a circle, rounded to the nearest tenth (1 decimal place). The starter code already prompts the user and takes in the radius as a double-value input. You need to do the calculations and print the results. I recommend using the printf() command (described in chapter 3 of the book) to print the results with the correct rounding. import java.util.Scanner; class Circle { static Scanner sc = new Scanner(System.in);...