0
Can someone explain the first loop for me please?...i didn't understand the "counter" thing??
31 Antworten
+ 2
One is old, one is new.
There are many more differences though.
You can search it up on the internet.
+ 2
code?
+ 2
the first loop of what?
+ 2
ok
+ 2
As long as the counter is less than or equal to the max index of the list, it prints the word with an exclamation mark.
+ 2
as list indices starts from 0, we do len(word) -1 to get the index of the last element.
+ 2
Why don't you try it?
+ 2
in counter = 1, it will start from the second element and so on.
+ 2
You can. It still works.
+ 1
the counter is used to iterate over the list words.
+ 1
and what if i write counter = 1
+ 1
or counter = 2
+ 1
notice we add 1 to the counter at the end of each loop.
+ 1
we add 1 so that the while loop doesn't keep going on for infinitely long.
+ 1
thank you i guess im starting to understand it a little
+ 1
thank you for the explanation
+ 1
Another thing: We can do it more easily using a for loop
words = ["hello", "world", "spam", "eggs"]
for word in words:
print(word + "!")
But I don't want to confuse you more!
+ 1
you're welcome!
+ 1
ok i guess i still have a long way to learn
+ 1
I am talking about Python 3 BTW