-3

Hello I am a python beginner and I am actually writing a programm which calculates the area of an circle by asking the user for an radius. My Problem: The ouput is like this '47529.15525615998' So my question is how to shorten the output so that it would be for example '47529.155'?

  • Here is my code:

    import math

    def compute_area(r):

    area=(r*r)*math.pi

    print(float(area),("Centimeter"))

    r=(float(input("Radius: ")))

    compute_area(r)

1 Answers1

0

use the following format to truncate float ("%.Nf") N=number of points after .

print("%.3f" %float(area),("Centimeter"))

Khan
  • 55
  • 11