0

How this code works?

Python sololearn challenge https://code.sololearn.com/cSZ5WMJJNbRo/?ref=app

30th Aug 2021, 12:14 PM
alagammai uma
alagammai uma - avatar
5 Respostas
+ 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
30th Aug 2021, 12:22 PM
A͢J
A͢J - avatar
+ 2
Try printing out the values in and out of the loop to see how it works.
30th Aug 2021, 12:17 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
30th Aug 2021, 12:37 PM
alagammai uma
alagammai uma - avatar
+ 1
2*2 =4 4*4 = 16 16*16 = 256 stopped after 3 time because in range(3)
30th Aug 2021, 12:43 PM
Jamal Game
Jamal Game - avatar
0
Jamal Game thank you
30th Aug 2021, 12:49 PM
alagammai uma
alagammai uma - avatar