Saturday, July 2, 2022

Python - Math

# Built-in math functions

myValues = (5, 10, 25)

# minimum, maximum
x = min(myValues)
y = max(myValues)

# 5, 25
print(x)
print(y)

# Absolute value
x = abs(-7.25)
# 7.25
print(x)

# x to the power of y
z = pow(4,3)
# 64
print(z)

print("----")


# Imported math functions
import math

x = math.sqrt(64)
print(x)

# Ceiling = round up to nearest integer
# Floor = round down to nearest integer

x = math.ceil(1.4)
y = math.floor(1.4)

# 2, 1
print(x)
print(y)

# PI is a constant (3.14....)
x = math.pi
# 3.14....
print(x)