LearnFrenzy
Sign in Take a free test

Tuples · Find the Error · Question 1

Error: assigning to a tuple item Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

The program below stops with an error. Which statement correctly describes the problem?

main.py
resolution = (1920, 1080)
resolution[0] = 1280
print(resolution)
  • A IndexError: index 0 out of range
  • B It prints (1280, 1080)
  • C TypeError: tuples are immutable; build a new tuple: resolution = (1280, resolution[1]) Correct
  • D ValueError: 1280 is too small
Correct Answer: Option C

Rebind the name to a new tuple, or use a list if the values must change.

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