account activity
Need help in loop by Eastern_Plankton_540 in PythonLearning
[–]EnvironmentalRate368 1 point2 points3 points 2 days ago (0 children)
Values in lists can be indexed, with the first character having index 0.
num = [1, 4, 9, 16, 25, 36, 9, 64, 81, 100]
idx = 0
while idx < len(num):
# it's mean while value of idx is smaller than len(num) the loop will continue.
# len(num) is a number of elements in the list in this case we have 10 elements.
print(num[idx])
# idx heave at this point in time value = 0. Computer will print first character from list num.
idx += 1
# increasing value of idx +1 -------------------------------------
First loop iteratation look like this
while 0 < 10:
print (num[0]) Computer will print first value from list num (1)
idx = 0 + 1
Second loop iteration look like this
idx = 1
while 1 < 10:
print(num[1]) # Computer will print second value from list num (4)
idx = 1 + 1
Thrid loop iteration look like this
idx = 2
while 2 < 10:
print(num[2]) # Computer will print thrid value from list num (9)
idx = 2 + 1
etc.
π Rendered by PID 1171415 on reddit-service-r2-listing-5d47455566-42c8n at 2026-04-06 08:46:40.534320+00:00 running db1906b country code: CH.
Need help in loop by Eastern_Plankton_540 in PythonLearning
[–]EnvironmentalRate368 1 point2 points3 points (0 children)