-2

I intend to print the fourth number of digits that the user intends to print up to 4 decimal places in the output How do I get up to four decimal places without using Round() function?

import math 
n = int(input('Do you want to calculate the root of a few numbers? --> '))

for i in range(n):
    usrinp = int(input('Enter the number for root --> '))
    x = math.sqrt(usrinp)

    print(x)

for example:

Do you want to calculate the root of a few numbers? --> 4

Enter the number for root --> 1

Enter the number for root --> 2

Enter the number for root --> 3

Enter the number for root --> 19


output:

1.0000

1.4142

1.7320

4.3588

Ali Zareei
  • 23
  • 5

1 Answers1

0

To get 4 decimal places without round function:

print('{:0.4f}'.format(x))
Austin
  • 25,759
  • 4
  • 25
  • 48