0
Please I don't understand how the codes on each item in a list is performed, can someone explain pls?
loops
4 Antworten
+ 4
Your code does not make a whole lot of sense, so I assume you meant
words=["hello","world","spam","eggs"]
counter=0
max_index=len(words)-1
while counter <=max_index:
word=words [counter]
print (word+"i")
counter=counter+1
while checks if the condition is true, if yes it executes the indented block and then checks the condition again until the condition is not true anymore.
In the first iteration counter is 0, then word is "hello" and "helloi" is printed.
Then counter is 1, word is "world. In the fourth iteration counter will be 3, so the code prints "eggsi". And after that counter is increased to 4. The condition counter<=max_index is now false and the loop will not be executed another time.
+ 4
please provide code.
0
words=["hello","world","spam","eggs"]
counter=0
max_index=len(words)-1
while counter <=max.index:
word=words [counter]
print (word+"i")
counter=counter+1
0
thanks tobi