0
Why is this giving no output?
import math def exp(x): return sum([ x**n / math.factorial(n) for n in range(0, 100) ]) exp(1)
3 Answers
+ 2
i think you need to assign exp() to a varaible and print it. like:
n=exp(1)
print(n)
+ 2
You don't have to assign anything. Since exp() just returns a value, print that returned value. Last line should be:
print(exp(1))
0
Tarun Doesn't your code work just fine? Here's the simplified version of your code:
import math
def exp(n):
return sum(x ** n / math.factorial(n) for n in range(100))