Select the correct output for the following Python code. for i in range(6, 1,…

2023

Select the correct output for the following Python code.

for i in range(6, 1, -2):
    print(end='*$$')

Answer: C. *$$*$$*$$ConceptIn Python, range(start, stop, step) includes start, excludes stop, and repeatedly adds step while values remain within the stopping condition. A print…

  1. A.

    *$$*$$

  2. B.

    *$$ *$$ *$$

  3. C.

    *$$*$$*$$

  4. D.

    *$$ *$$

Attempted by 2176 students.

Show answer & explanation

Correct answer: C

Concept

In Python, range(start, stop, step) includes start, excludes stop, and repeatedly adds step while values remain within the stopping condition.

A print call with no objects emits only its end string; supplying end also replaces the default newline.

Application

  1. For range(6, 1, -2), begin at 6 and subtract 2 each time. The generated values are 6, 4, 2; the next value 0 is below the exclusive stop boundary, so there are three iterations.

  2. On each iteration, print(end='*$$') has no object argument, so it emits exactly *$$ through the end parameter.

  3. Because the end string contains neither a space nor a newline, the three emitted segments are adjacent: *$$*$$*$$.

Cross-check

A trace gives one emitted segment for each loop value:

Loop value

Emitted text

6

*$$

4

*$$

2

*$$

Therefore, the output is *$$*$$*$$.

Explore the full course: Rssb Senior Computer Instructor

Loading lesson…