LearnFrenzy
Sign in Take a free test

Lists · Find the Error · Question 7

Bug: "last three" gives two items Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 7 Back to Exercise

The program should print the last three readings. Which statement correctly identifies the bug?

main.py
readings = [31, 29, 33, 35, 30, 28]
print(readings[-3:-1])
  • A Negative indexes count from the start
  • B The stop index -1 excludes the last item; write readings[-3:] Correct
  • C Slices cannot use negative numbers
  • D It should be readings[3:-1]
Correct Answer: Option B

A slice stops before its stop index; leave it out to go to the end.

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