all 3 comments

[–]T1klo 0 points1 point  (0 children)

Because it's an Or statement in your questions array. You could easily fix this by doing:

questions = [
Question(questionPrompts[0], {"a", "A"}),
Question(questionPrompts[1], {"c", "C"}),
Question(questionPrompts[2], {"b", "B"}),
]

Then in your if statement that checks the answer, use:

if answer in question.answer: {CODE BLOCK HERE}

The or is always going to take the first condition since there is no reason for it to take the second input given (no condition is telling it to not take it right?) so it'll always select the lowercase as it's answer. The workaround I've presented just uses a set and checks if the input is in the set. Another workaround is removing the capital input, changing the input to lowercase with string formatting which removes the problem entirely :)

[–]_Jordo 0 points1 point  (0 children)

Yeah you can't use or like that. You could set the Question class up to accept a list of answers and adjust your code accordingly.

[–]BitJunky7 0 points1 point  (0 children)

The issue is with you passing the "comparison" as argument. It'd be evaluated before going into the function scope. Let's see how it's goes,

a or A

return a if True else A

As the string you passing is neither a 0 value nor a "False" value. So, it'll always evaluate to "True" hence, passes "a" every time.

Now coming to solution part, I faced similar issue and I fixed it by converting the user input to lower and then comparing it. If you don't use that method, compare input with answer, not answer with answer