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 of a loop to perform n calculations for the user: 5
pts
Correct use of value-returning functions inside a loop structure:
10 pts
Sample Output:
Enter n: 3
Enter r: 34
Area is: 3633.14285714
Enter r: 23
Area is: 1662.57142857
Enter r: 43
Area is: 5811.1428571
Source Code:
Output:
Code in text format (See above image of code for indentation):
#function definition to calculate area
def area(r):
#calculate area and return area
a=(22/7.0)*r*r
return a
#main function
def main():
#read n value from user
n=int(input("Enter n: "))
#using loop calculate area some n times
for i in range(n):
#read radius r from user
r=float(input("Enter r: "))
#print area by calling function
print("Area is: ",area(r))
#main function call
if __name__=="__main__":
main()
Get Answers For Free
Most questions answered within 1 hours.