+ 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

1st Jul 2019, 11:52 AM
Chethan Abishek
Chethan Abishek - avatar
4 Antworten
+ 2
It is a strange code, I would write it like this: words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!")
1st Jul 2019, 12:10 PM
Paul
Paul - avatar
+ 2
If you don't include this code, we can't explain what the heck it is
1st Jul 2019, 11:53 AM
Airree
Airree - avatar
+ 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
1st Jul 2019, 12:00 PM
Pete Cowling
Pete Cowling - avatar
+ 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)
1st Jul 2019, 12:08 PM
Júlia
Júlia - avatar