In this question, you will experimentally verify the sensitivity of using a precise Pi to the accuracy of computing area. You need to perform the following activities with Python program:

a. Compute the area of a circle with radius 10 using Pi from the Python Math Module. Assign the area to a variable, say realA.
b. Now compute the area of the circle using the Pi value with precision 1,2, and 3 points after the decimal place. (i.e., Pi = 3.1, 3.14 & 3.141). Then Print the percentage difference between each of the areas calculated using each of these values of Pi and realA.

Respuesta :

Answer:

Follows are the code to this question:

import math as x #import math package

#option a

radius = 10#defining radius variable  

print("radius = ", radius)#print radius value

realA = x.pi * radius * radius#calculate the area in realA variable

print("\nrealA = ", realA)#print realA value

#option b

a1 = 3.1  * radius * radius#calculate first area in a1 variable  

print("Area 1= ", a1)#print Area

print("Percentage difference= ", ((realA - a1)/realA) * 100) #print difference  

a2 = 3.14  * radius * radius#calculate first area in a2 variable                            

print("Area 2= ", a2)#print Area

print("Percentage difference= ", ((realA - a2)/realA) * 100)#print difference  

a3 = 3.141  * radius * radius#calculate first area in a2 variable                       print("Area 3= ", a3)#print Area

print("Percentage difference= ", ((realA - a3)/realA) * 100) #print difference  

Output:

please find the attached file.

Explanation:

In the given Python code, firstly we import the math package after importing the package a "radius" variable is defined, that holds a value 10, in the next step, a "realA" variable is defined that calculate the area value.

In the next step, the "a1, a2, and a3" variable is used, which holds three values, that is "3.1, 3.14, and 3.141", and use the print method to print its percentage difference value.  

Ver imagen codiepienagoya