+ 1
Hey guys I didnt understand the heck this code is....can anyone explain it to me???
words = ["hello", "world", "spam", "eggs"] counter = 0 max_index = len(words) - 1 while counter <= max_index: word = words[counter] print(word + "!") counter = counter + 1
4 Réponses
+ 2
It is a strange code, I would write it like this:
words = ["hello", "world", "spam", "eggs"]
for word in words:
print(word + "!")
+ 2
If you don't include this code, we can't explain what the heck it is
+ 2
It prints all elements of a list or whatever is indexed. Try it in the code playground. Also your profile pic is great, Messi is the best
+ 1
There are an array of 4 positions. A counter with the value 0, and max_index with the value of 3.
The while loop will be executed 4 times. Inside the loop, you will print:
Hello!world!spam!eggs!
Because you put the word of the counter position, and you print it.
And increment the counter, while it was less or equal to max_index (4)