-1

I want to make a function pi(d), where "d" tells how many decimals pi should return. If "d" is bigger than 15, it should include 15 decimals. If "d" is empty(pi(d)), pi should include 2 decimals. I have tried:

import math

def pi(x):
    if x>15:
        print(math.pi)
    elif x=="":
        print(round(math.pi, 2))
    else:
        print(round(math.pi, x))

What is wrong?

1 Answers1

0

i mean omitted

So, you mean: How do I create a Python function with optional arguments?

In your case:

def pi(x=2):
    if x>15:
        print(math.pi)
    else:
        print(round(math.pi, x))

pi()
Armali
  • 18,255
  • 14
  • 57
  • 171