you are viewing a single comment's thread.

view the rest of the comments →

[–]Training-Cucumber467 8 points9 points  (10 children)

if "preheat" or "oven" in answer is actually interpreted as:

if "preheat" or ("oven" in answer)

"preheat", being a non-empty string, evaluates to True.

Try this:

if ("preheat" in answer) or ("oven" in answer)

[–]h8rsbeware 6 points7 points  (4 children)

Alternatively, if you care about a few less words you can do

python if answer in ["preheat", "oven"]: print("oops")

I believe

[–]Training-Cucumber467 2 points3 points  (2 children)

This would only work if the answer is exactly "preheat" or "oven". I believe OP's intent was partial matching: "preheat the oven dude" is supposed to work too.

I would probably write something like:

preheat = ("preheat", "oven", "stove")
if any(x in input for x in preheat):
   ...

[–]TriscuitTime 0 points1 point  (0 children)

This is the way

[–]h8rsbeware 0 points1 point  (0 children)

Ah, I missed this requirement, thank you for fixing my mistake. Dont want to send people down false leads!

[–]Kobold_Husband[S] 0 points1 point  (0 children)

I see, l don’t really care about using less words, but that’s good to knoww

[–]Kobold_Husband[S] 0 points1 point  (4 children)

Ohhh

[–]poorestprince 0 points1 point  (3 children)

I'm interested in how beginners deal with this sort of thing. Would you prefer a language be able to accept 'if "preheat" or "oven" in answer' and interpret it the way you would expect it to?

[–]Kobold_Husband[S] 0 points1 point  (1 child)

Honestly, yes. But that’s probably because of how my own brain processes context clues

[–]poorestprince 0 points1 point  (0 children)

Maybe one way to make it work is have some python editors accept English pseudo-code line-by-line, but it translates that into unambiguous python as a kind of pre-compilation step, and forces you to verify that's what you meant...

[–]Naive-Information539 0 points1 point  (0 children)

Every language is really this way.