Write a function called truncate It is passed 2 parameters a

Write a function called truncate. It is passed 2 parameters, a float f and an integer d. The function truncates f so that it has d digits to the right of the decimal point. For example:

>>> truncate (line_length ( (0,1), (1,0)), 3)

1.414

>>> truncate(circle_circumference(1), 1)

6.2

>>> truncate(circle_area(1), 4)

3.1415

Solution


import math

def circle_area(r):#function to find area of circle
   return math.pi*r*r
def circle_circumference(r):#function to find circumference of circle
   return math.pi*r*2

def truncate(f,d):#truncate d digits in f
   s=\"%.\"+str(d)+\"f\"
   return s % (f)


print truncate(circle_area(1),4)
print truncate(circle_circumference(1),1)

=================================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ python flo.py
3.1416
6.3

Write a function called truncate. It is passed 2 parameters, a float f and an integer d. The function truncates f so that it has d digits to the right of the de

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site