18 lines
501 B
Python
18 lines
501 B
Python
from mpmath import mp
|
|
|
|
def pi_decimals(n):
|
|
"""
|
|
Renvoie π avec n décimales.
|
|
:param n: nombre de décimales souhaitées
|
|
"""
|
|
# Définir la précision : on ajoute quelques chiffres supplémentaires pour éviter l'arrondi
|
|
mp.dps = n + 2
|
|
return str(mp.pi)[:n+2] # "3." + n chiffres
|
|
|
|
# Exemple d'utilisation :
|
|
if __name__ == "__main__":
|
|
n = int(input("How many decimal of pi you want ? "))
|
|
valeur_pi = pi_decimals(n)
|
|
print(f"π with {n} decimal :\n{valeur_pi}")
|
|
|