0
How this code works?
Python sololearn challenge https://code.sololearn.com/cSZ5WMJJNbRo/?ref=app
5 Answers
+ 2
alagammai uma
range(3) returns list [0, 1, 2 ] and list has size 3 so for loop will work 3 times
1st time, x = x**2 = 2**2 = 4, now x is 4
2nd time, x = 4**2 = 4 * 4 = 16, now x is 16
3rd time, x = 16**2 = 16 * 16 = 256, now x is 256 which is final result
Here ** is exponential operator which means power of any number like x**y here y is the power of x
+ 2
Try printing out the values in and out of the loop to see how it works.
+ 1
2*2 =4 4*4 = 16 16*16 = 256
stopped after 3 time because in range(3)
0
Jamal Game thank you