Python Editor

Python | Lesson4 | Math Module


import math

# square root of a number
x = 16
print("The square root of", x, "is", math.sqrt(x))

# max of two numbers
c = 4
d = 8
print("The max of", c, "and", d, "is", max(c, d))

# floor of a decimal number
e = 3.14159
print("The floor of", e, "is", math.floor(e))

# round off a decimal number to nearest integer
f = 2.71828
print("The round off of", f, "is", round(f))

# sine of an angle
y = math.pi/4
print("The sine of", y, "is", math.sin(y))

# cosine of an angle
z = math.pi/3
print("The cosine of", z, "is", math.cos(z))

# natural logarithm of a number
a = 2.71828
print("The natural logarithm of", a, "is", math.log(a))

# base 10 logarithm of a number
b = 100
print("The base 10 logarithm of", b, "is", math.log10(b))

No comments:

Post a Comment