+ 1
Can anyone please explain this code..
def f(a): j=range(1,a+1) b=eval("**".join([str(i)for i in j])) return b print(f(3)) output is 1 how??
4 Answers
+ 1
Hello!
This code just power 1 in range a+1. So it doesn't matter which a you input it will be 1 anyway.
Hope it helps you.
+ 1
def f(a):
j = range(1, a+1) # for a = 3, j = [1, 2, 3]
b = eval("**".join([str(i) for i in j])) # results in b = eval('1**2**3') which is 1
return b # b will be 1 for any parameter
0
thank you
0
j=(1,2,3)
b=eval('1**2**3')
b=1**2**3 (pow(2,3))(1 raise to the power 2 raise to the power 3)
b=1**8
b=1