← Back to challenges

Pi to N Decimal Places

PythonHardmathnumbers

Instructions

Given a number n, write a function that returns PI to n decimal places.

Examples

my_pi(5) ➞ 3.14159

my_pi(4) ➞ 3.1416

my_pi(15) ➞ 3.141592653589793

Notes

  • n will not be above 15, to keep this challenge simple.
  • Round up the last digit if the next digit in PI is greater or equal to 5 (see second example above).
  • The return value must be a number, not a string.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Odd Up, Even Down