0
I want to know how to change this to while loop. Please help.
6 Answers
+ 1
scores = [("mia", 75), ("lee", 90)]
size = len(scores)
index = 0
while index < size:
print(f"Result: {scores[index]}")
index += 1
+ 2
XXX yes but I wanted to understand all those concepts really well. So I thought figuring out an alternative way and asking someone would give me better learning experience.
+ 2
Abdus Sattar
Yeah that's why I said, "just learning the concepts is not enough, you'll have to know where a specific concept will apply better than the others"
Your approach is good, of using alternative methods to get the same result. But I'm just saying along with knowing a concept, you have to know where to use the concept. For example, for-loops are meant for iterating on iterables (like list), so they should be preferred over while-loops in such cases.
Happy coding!
+ 1
But why? For loops are meant for iterating over iterables and it makes no sense to change it to a while loop. Just learning the concepts is not enough, you'll have to know where a specific concept will apply better than the others.
- 1
while index < size:
print(f"Result: {scores[index]}")
index += 1