+ 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??

5th Jul 2018, 12:32 PM
Supriya Gangapatnam
Supriya Gangapatnam - avatar
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.
5th Jul 2018, 12:46 PM
dev.Y
dev.Y - avatar
+ 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
5th Jul 2018, 12:49 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
thank you
5th Jul 2018, 12:48 PM
Supriya Gangapatnam
Supriya Gangapatnam - avatar
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
5th Jul 2018, 12:48 PM
Pulkit Kamboj
Pulkit Kamboj - avatar