Loop in Python: While loops: Lists - asking

The quiz ask me to use while loop and print out the string “I am learning about (element from python_topics)”
but when I wrote length > index (conditional statement) → It’s wrong
but when I wrote index < length → It’s right
I’m really confuse. Am I wrong or the answer for this quiz must be index < length or something else?
python_topics = [“variables”, “control flow”, “loops”, “modules”, “classes”]
My code:
length = len(python_topics)
index = 0
while index < length:
print("I am learning about " + str(python_topics[index]))
index += 1


Your code is correct and I have no problem on the task with it.

Using length > index would also work.
Sometimes the checks are picky.
Although it didn’t specify which way round it would like the conditional statement, the examples above used:

while index < length:

It’s best to stick to what the examples show.

Hope that helps!

1 Like

I think stick to what the examples show is good but it’s pretty simple and the applicability is not high. I try to do something else to test is it work out or not. But anyway, thank you