4 Antworten
+ 5
Let's start from the loop part. It iterates over every character of the word (python). So there will be 6 iterations which is the length of the word.
Inside the loop it add x as a string to y and increment the value of x and it will print y.
So actually the answer is like this
1
12
123
1234
12345
123456
+ 5
Thanks both of you
The explanation Abhinaya
+ 3
The code goes through the word python letter by letter, and increases x by one for each letter there (for i in word), then prints y (which is x as a string) plus the new x as a string.
i in word = p;
y = "1";
x+=1 = 2;
i in word = y;
y = "1" + "2" = "12"
x+=1 = 3;
...and so on, until the end of the word when the loop ends.