for loop 3 times python code example
Example 1: python for loop 2 items at a time
# ------------- For loop using 2 items of a list --------------- #
# This code is trying to find if a point belongs between
# the interval of pairing points of a list:
mylist = [117, 202, 287, 372, 457, 542]
point = 490
# 117 < x < 202 ?
# 287 < x < 372 ?
# 457 < x < 542 ?
for i, j in zip(mylist[::2], mylist[1::2]):
if i < point < j:
print ("This point exists between: ", i, " - ", j)
break
Example 2: python loop certain number of times
# To loop n times, use loop over range(n)
for i in range(n):
# Do something
Example 3: how to run loops 3 times in python
number1 = 0
number2 = 0
number3 = 0
for i in (number1, number2, number3):
i = int(input("Enter number: "))