I want to know how to change this to while loop. Please help. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I want to know how to change this to while loop. Please help.

https://code.sololearn.com/cdixmdsbOq5S/?ref=app

27th May 2021, 4:38 PM
Abdus Sattar
Abdus Sattar - avatar
6 Answers
+ 1
scores = [("mia", 75), ("lee", 90)] size = len(scores) index = 0 while index < size: print(f"Result: {scores[index]}") index += 1
27th May 2021, 4:48 PM
visph
visph - avatar
+ 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.
27th May 2021, 5:00 PM
Abdus Sattar
Abdus Sattar - avatar
+ 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!
27th May 2021, 5:36 PM
XXX
XXX - avatar
+ 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.
27th May 2021, 4:48 PM
XXX
XXX - avatar
+ 1
XXX visph Thank you very much
27th May 2021, 5:01 PM
Abdus Sattar
Abdus Sattar - avatar
- 1
while index < size: print(f"Result: {scores[index]}") index += 1
29th May 2021, 4:21 PM
Ishika Bhatia
Ishika Bhatia - avatar