Module math


Ce module fournit l'accès aux fonctions mathématiques définies par la norme C.

import math
x = 12.95
y = -4.2

print(math.floor(x))

print(math.fabs(y))

print(math.ceil(x))
12
4.2
13
a = 2
b = 16

# Élévation à la puissnace
print(math.pow(a, 3))

# Racine carré
print(math.sqrt(b))
8.0
4.0
# Dénombrement
n = 5
k = 2

# Le factoriel
print(math.factorial(5))

# Nombre de combinaisons
# print(math.comb(n, k))

# Nombre de premutations
# print(math.perm(n, k))
120
# Trigonométrie
theta = 0.53

# Valeur du nombre pi
print(math.pi)

# Conversion de dégrés en radians
print(math.radians(180))

# Cosinus de 0
print(math.cos(0))

# Sinus de pi
print(math.sin(math.pi))

print(math.sin(theta)**2 + math.cos(theta)**2)
3.141592653589793
3.141592653589793
1.0
1.2246467991473532e-16
1.0
# Logarithme et Exponentiel

print(math.exp(0))

print(math.exp(1))

print(math.log(1))

print(math.log(math.exp(5)))

print(math.exp(math.log(5)))
1.0
2.718281828459045
0.0
5.0
4.999999999999999

Pour en savoir plus, merci de consulter la documentation officielle de Python.

Partagez sur les réseaux sociaux

Commentaires