CBSE Class 12 Computer Science Question 74 of 105

Python Revision Tour — Question 28

Back to all questions
28
Question

Question 27

Write the output of the following Python code:

for i in range(2,7,2):
    print(i*'$')
Answer
Output
$$
$$$$
$$$$$$
Explanation

range(2,7,2) returns [2, 4, 6] as it defines a range of 2 to 6 with a step of 2. The loop iterates as below:

  • For i = 2, it prints $$.
  • For i = 4, it prints $$$$.
  • For i = 6, it prints $$$$$$.