sqrt()

sqrt(x) returns squqre root of input number as float data type.
import math
print(math.sqrt(4))    # 2.0 
print(math.sqrt(16))   # 4.0 
print(math.sqrt(20))   # 4.47213595499958
print(math.sqrt(0))    # 0.0
Using negative number
For any value less than 0 , we will get ValueError
import math
print(math.sqrt(-15)) 
Above code will generate error.

Output of math.sqrt() is float data type. We can use type() to get the data type.
import math
x=math.sqrt(25)
print(x)        # 5.0
print(type(x))  # <class 'float'>
We can use int() to convert output to integer data type.
import math
x=math.sqrt(25)
y=int(x)
print(type(y))  # <class 'int'>
log10 modf()


plus2net.com



04-07-2020

Why the square root of 16 is 4.0 and why not 4???

05-07-2020

The output of sqrt is float always. Added the part to convert float data type to integer.

Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer