0

How can I replace the while loop in this code with the for loop?

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

26th May 2021, 8:52 PM
Abdus Sattar
Abdus Sattar - avatar
10 Respuestas
+ 4
comment or remove the index initialization (index = 0), as well as the index incremention (index += 1), because you doesn't need both with a for loop... then replace or comment the while loop with or add the for statement: for index in range(len(classes)): previous answer saying len()-1 is wrong ^^
26th May 2021, 9:04 PM
visph
visph - avatar
+ 3
Ah. Yes you're right.
26th May 2021, 9:09 PM
Simon Sauter
Simon Sauter - avatar
+ 2
Simon Sauter you're wrong: the end parameter of a range object is excluded from the count ^^
26th May 2021, 9:08 PM
visph
visph - avatar
+ 1
sure :D
26th May 2021, 9:10 PM
visph
visph - avatar
+ 1
Thank you very much to both of you.
26th May 2021, 9:26 PM
Abdus Sattar
Abdus Sattar - avatar
+ 1
# 2 i = 0 for name in classes: scheduled_class = name+": "+times[i] i += 1
26th May 2021, 9:36 PM
Solo
Solo - avatar
+ 1
Netha_r2071 Thank you. I have not gone so far in learning. Thanks. I will try the above very soon after I learn these parts of coding. Thanks again.
27th May 2021, 1:35 PM
Abdus Sattar
Abdus Sattar - avatar
0
You could use zip function ,and print the tuples
27th May 2021, 1:33 PM
RuntimeERROR
RuntimeERROR - avatar
- 2
for index in range(len(classes)-1):
26th May 2021, 8:56 PM
Simon Sauter
Simon Sauter - avatar
- 2
I added the "-1" because his while loop has a "<". If it was "<=" I would agree with you.
26th May 2021, 9:07 PM
Simon Sauter
Simon Sauter - avatar