0

Hello everyone! could somebody interpret this code?

x = 2 for i in range(3): x/2 print(x)

16th May 2022, 5:06 PM
Emmanuel Baah
Emmanuel Baah - avatar
3 Respostas
+ 2
x = 2 # assigns 2 to x Your loop runs 3 times from i=0 to 2 but x/2 does not effect anything. print(x) prints 2 if you want use x/2 in effect stores it's value may back in x like x=x/2 #run this code and observe output x = 2 for i in range(3): x = x/2 print("i=", i, "x=", x) print(x) Hope it helps..
16th May 2022, 5:17 PM
Jayakrishna 🇮🇳
+ 1
interesting. okay, let me do that.
16th May 2022, 5:23 PM
Emmanuel Baah
Emmanuel Baah - avatar
+ 1
woah! prints three times. starts from starting from 1 = 0 to i = 2. i see it .
16th May 2022, 5:25 PM
Emmanuel Baah
Emmanuel Baah - avatar