For Loop
For Loop
For Loop
For Loop
Mathematical Problem Formulation
Understanding Python's range() Function
range(6): Generates a sequence of integers from 0 to 5 (inclusive of 0 but exclusive of 6).
Iteration with for Loop:
for number in range(6): Iterates over each integer in the sequence.
Print the Current Integer:
print(number): Prints the current integer on each iteration.
For Loop
Mathematical Problem Formulation
range(1, 10, 2): Generates a sequence of integers starting from 1 up to (but not including) 10, with a step of 2. This means it will include every second number starting from 1 to 9.
for number in range(1, 10, 2): Iterates over each integer in the sequence produced by range(1, 10, 2).
For Loop
For Loop
For Loop
For Loop
Mathematical Problem Formulation
Outer Loop (for i in range(1, 4)):
The outer loop goes through numbers \(1\), \(2\), and \(3\).
range(1, 4) means "start at \(1\) and go up to (but not including) \(4\)." So, it will produce the numbers \(1\), \(2\), and \(3\).
Inner Loop (for j in range(10, 13)):
For each value of \(i\) from the outer loop, this inner loop goes through numbers \(10\), \(11\), and \(12\).
range(10, 13) means "start at \(10\) and go up to (but not including) \(13\)." So, it produces the numbers \(10\), \(11\), and \(12\).
Output of Nested Loops
First Group: When i = 1:
It prints 1 with 10, 11, and 12.
Second Group: When i = 2:
It prints 2 with 10, 11, and 12.
Third Group: When i = 3:
It prints 3 with 10, 11, and 12.