LearnFrenzy
Sign in Take a free test

Operators and Expressions · Find the Error · Question 6

Bug: grade == "A" or "B" Answer, explanation & discussion

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

A student with grade C is told they have a distinction. Which statement correctly identifies the bug?

main.py
grade = "C"
if grade == "A" or "B":
    print("Distinction")
else:
    print("Keep working")
  • A Strings cannot be compared with ==
  • B else must be elif
  • C grade should be lowercase
  • D The condition is (grade == "A") or "B", and the non-empty string "B" is always truthy; write grade in ("A", "B") Correct
Correct Answer: Option D

or does not distribute over ==. Each comparison must be written in full, or use in.

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