Page 263 - CTS - CSA TP - Volume 2
P. 263
COMPUTER SOFTWARE APPLICATION - CITS
Output:
TASK 2: Python For Loop with a step size
Code:
limit=int(input(“Enter the Limit: “))
fori in range(0, 20, 2):
print(i)
Explanation:
This code uses a for loop in conjunction with the range() function to generate a sequence of numbers starting
from 0, up to (but not including) limit, and with a step size of 2. For each number in the sequence, the loop prints
its value using the print() function.
Output:
TASK 3: Python For Loop inside a For Loop
Code:
limit=int(input(“Enter the Limit: “))
fori in range(1, limit):
for j in range(1, limit):
print(i, j)
Explanation:
This code uses nested for loops to iterate over two ranges of numbers (1 to limit inclusive) and prints the value
of i and j for each combination of the two loops. The inner loop is executed for each value of i in the outer loop.
Output:
248
CITS : IT & ITES - Computer Software Application - Exercise 126