0

words = ["hello", "world", "spam", "eggs"] counter = 0 max_index = len(words) - 1 while counter <= max_index: word = words

I can't understand about 'counter=0' and. "while counter <= max_index:word = words" and this please explain about this to me!!!!!!!

11th Jun 2018, 4:20 PM
Anurag
Anurag - avatar
4 Respuestas
+ 1
What ist the purpose of your Code? What Output do you expect?
11th Jun 2018, 7:36 PM
Sebastian Keßler
Sebastian Keßler - avatar
+ 2
What it does: words = ["hello", "world", "spam", "eggs"] # defines a List of 4 Words counter = 0 # defines an integer that is Zero max_index = len(words) - 1 # defines another integer that is 3 while counter <= max_index: # Starts a Loop that will Stop when the condition is true word = words # creates a Copy of the List The Loop will run Infinite. There will be no Output. What can you do? Print all Words in your List with the number of Characters: words = ["hello", "world", "spam", "eggs"] counter = 0 max_index = len(words) - 1 while counter <= max_index: print (words[counter], len (words[counter])) counter += 1 Or better: words = ["hello", "world", "spam", "eggs"] for i in words: print (i, len (i))
12th Jun 2018, 6:01 PM
Sebastian Keßler
Sebastian Keßler - avatar
0
actually what it can do
12th Jun 2018, 3:56 PM
Anurag
Anurag - avatar
0
thanks
12th Jun 2018, 11:15 PM
Anurag
Anurag - avatar