LearnFrenzy
Sign in Take a free test

Loops · Predict the Output · Question 1

Three forms of range() Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

What is the output of the following Python program?

main.py
print(list(range(5)), list(range(2, 10, 3)), list(range(10, 0, -4)))
  • A [1, 2, 3, 4, 5] [2, 5, 8] [10, 6, 2]
  • B [0, 1, 2, 3, 4] [2, 5, 8, 11] [10, 6, 2, -2]
  • C [0, 1, 2, 3, 4] [2, 5, 8] [10, 6, 2] Correct
  • D [0, 1, 2, 3, 4, 5] [2, 5, 8] [10, 6]
Correct Answer: Option C

The stop value is never included: 11 is past 10, and -2 is past 0 when counting down.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links