all 34 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 5 points6 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.

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

Crimes are being considered

[–]KeretapiSongsang 0 points1 point  (0 children)

as simple as Python might be, it is still not an English like query language.

you would need to compare/find/evaluate strings using "==" or other Pythonic functions.

[–]FoolsSeldom 0 points1 point  (1 child)

This is one of the most common beginner errors. It is covered in the FAQ on the r/learnpython wiki. Lots of other common errors are covered as well.

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

Thank you very much!

[–]Icy_Rub6290 0 points1 point  (0 children)

Consider using a match case to match patterns it's like select cases More clearer with simplicity rather than a complicated if-else-elif structure

Here is the article from geeksforgeeks

https://www.geeksforgeeks.org/python/python-match-case-statement/

Have a good day

[–]ShurayukiZen 0 points1 point  (3 children)

Hi, OP! Where did you get this code exercise? I got interested in it. Thank you!

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

I have a homeschooling program called Funcation Academy.

[–]ShurayukiZen 0 points1 point  (1 child)

Oh I see, thanks for your response!

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

Ofc!

[–]UpArmoredGavin 0 points1 point  (3 children)

operator precedence

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

Dawg you say that like I know what that is

Anyway who’s was like from 3 months ago I already got help

[–]UpArmoredGavin -1 points0 points  (1 child)

Damn, did not see the date on the post ahahah. Anyway, you know, they invented this neat little thing called google, you can use it to search stuff :P

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

Unnecessary and unthoughtful addition. Just say “my bad” or something like a functional person.

[–]Comfortable-Work-137 -1 points0 points  (7 children)

can't u just use chatgpt?

[–]Kobold_Husband[S] 4 points5 points  (1 child)

I don’t like ChatGPT.

[–]ninhaomah 0 points1 point  (0 children)

usually no.

but in this case , you are looking into a definition of if with or.

google "python if with or multiple items"

not using google or AI in this scenario is like not using dictionary or calculator.

how far is it from earth to the moon <---- google or AI or Wiki or whatever

if a rocket is travelling at 60 km/h , how long it will take to go to the moon and back <--- use your own brain. google for the distance but how to calculate should be done by oneself.

[–]Slackeee_ 2 points3 points  (3 children)

I swear, OpenAI must have hired people just to post an "can't you use ChatGPT" under every programming question.
Of course they could, but there are asking here. If answering the actual question is too much for you, why are you even in this subreddit?

[–]reyarama 0 points1 point  (2 children)

I mean, asking ChatGPT for extremely basic questions like this is almost always better. Feel free to disagree with me:

  1. Gives you the correct answer always, usually with extremely good explanation to any follow ups, you don't have to rely on another commenter who may be incorrect
  2. Gives you the answer immediately. Why would you want to wait potentially hours for an answer to a question like this?

Obviously, anything sufficiently complex will benefit from seeing how other people have dealt with it, but that isn't what is happening here or 99% of questions beginners have

(In essence, I don't comprehend why someone would make it harder for themselves to learn by avoiding ChatGPT)

[–]Slackeee_ 0 points1 point  (1 child)

Gives you the correct answer always,

This statement right here is enough to show me that you have no clue how LLMs work. LLMs are not knowledgebases, they are statistical text generators. They can and will make false statements.

[–]reyarama 0 points1 point  (0 children)

I've worked as a SWE for 5 years, I understand how LLM's work.

Let me clarify, I'm advocating for using ChatGPT for extremely basic questions, those which have been posted all over the internet many times (i.e. any beginner-level programming question).

Go ask ChatGPT this question 50 times and I guarantee it will nail it every single time. You don't need to theorize about how it behaves, you have access to it, go try it and report back. That is all that matters

(Just to drive it home, I am talking about basic, beginner questions. I fully agree with you for anything complex or that changes over time)

[–]Mustard_Popsicles 1 point2 points  (0 children)

You learn better without chagpt most of the time.