0
How can I replace the while loop in this code with the for loop?
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 ^^
+ 3
Ah. Yes you're right.
+ 2
Simon Sauter you're wrong: the end parameter of a range object is excluded from the count ^^
+ 1
sure :D
+ 1
Thank you very much to both of you.
+ 1
# 2
i = 0
for name in classes:
scheduled_class = name+": "+times[i]
i += 1
+ 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.
0
You could use zip function ,and print the tuples
- 2
for index in range(len(classes)-1):
- 2
I added the "-1" because his while loop has a "<". If it was "<=" I would agree with you.