LearnFrenzy
Sign in Take a free test

Tuples · Find the Error · Question 8

Error: index() of an absent value Answer, explanation & discussion

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

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

main.py
ranks = ("Asha", "Ravi", "Meera")
print("Kiran is rank", ranks.index("Kiran") + 1)
  • A It prints Kiran is rank 0
  • B It prints Kiran is rank -1
  • C ValueError: index() raises when the value is absent; check "Kiran" in ranks first Correct
  • D IndexError
Correct Answer: Option C

Tuples have no find(); test membership before calling index().

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