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)

26th Aug 2021, 5:43 AM
Tarun
3 Answers
+ 2
i think you need to assign exp() to a varaible and print it. like: n=exp(1) print(n)
26th Aug 2021, 5:48 AM
you are smart. you are brave.
you are smart. you are brave. - avatar
+ 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))
26th Aug 2021, 5:55 AM
Slick
Slick - avatar
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))
26th Aug 2021, 7:02 AM
Calvin Thomas
Calvin Thomas - avatar