LearnFrenzy
Sign in Take a free test

Dictionaries · Find the Error · Question 6

Bug: searching a value with in Answer, explanation & discussion

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

Someone did score 91, but the program says nobody did. Which statement correctly identifies the bug?

main.py
marks = {"Asha": 91, "Ravi": 78}
if 91 in marks:
    print("Someone scored 91")
else:
    print("Nobody scored 91")
  • A in on a dict checks the keys (names); use 91 in marks.values() Correct
  • B in only works on lists
  • C 91 must be a string
  • D The dict must be sorted first
Correct Answer: Option A

Membership, iteration and len() all work on keys by default.

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