0

Describing a While code

Would you describe the code, specially commented part ? https://code.sololearn.com/cuFz6oZNby4q/?ref=app

20th Jan 2018, 1:54 PM
NIMA
NIMA - avatar
1 Answer
+ 2
'''This part sets a list and a counter variable''' words = ["hello", "world", "spam", "eggs"] counter = 0 '''This part sets another variable to the length of the list. -1 because lists start at 0''' max_index = len(words) - 1 '''This is a while loop that runs until the counter is larger than the length of the list. Each run of it, it prints the next word from the list''' while counter <= max_index: word = words[counter] print(word + "!") counter = counter + 1
20th Jan 2018, 2:02 PM
LordHill
LordHill - avatar