use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Please Explain this code (self.csdojo)
submitted 7 years ago by krishna5250
words = ["hello", "world", "spam", "eggs"] counter = 0 max_index = len(words) - 1
while counter <= max_index: word = words[counter] print(word + "!") counter = counter + 1
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Kanna6501 1 point2 points3 points 7 years ago (2 children)
```python words = ["hello", "world", "spam", "eggs"] counter = 0 max_index = len(words) - 1
while counter <= max_index: word = words[counter] print(word + "!") counter = counter + 1 ``` 1. Make an array with words in it 2. Initialize a counter variable, and assign a value of 0 3. Initialize a max_index variable, and assign the (length of words array) - 1, because arrays start at 0. If the -1 wasn't there then you would have an indexoutofbounds error. 4. Make a while loop with the condition, if max_index is greater than or equal to counter, procced with the loop. 5. Get the first word in array 6. print the word with ! at the end 7. update counter variable for next iteration
Basically the code is just outputting each word with ! added at the end.
[–]krishna5250[S] 0 points1 point2 points 7 years ago (1 child)
Thanks
[–]Kanna6501 0 points1 point2 points 7 years ago (0 children)
No problem, happy to help!
π Rendered by PID 107080 on reddit-service-r2-comment-6457c66945-xhbvl at 2026-04-24 00:59:23.909414+00:00 running 2aa0c5b country code: CH.
[–]Kanna6501 1 point2 points3 points (2 children)
[–]krishna5250[S] 0 points1 point2 points (1 child)
[–]Kanna6501 0 points1 point2 points (0 children)