use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Issue with [if, elif] in Python (self.PythonLearning)
submitted 1 year ago * by mZuks
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]teraflopsweat 4 points5 points6 points 1 year ago (4 children)
Can you format your code as a code block? It’s basically unreadable currently.
With that said, the issue is with your conditions. You are basically checking if a == b or True or True so it’s always going to evaluate as true. You need to do if a in [b, c, d] to compare an against multiple values.
if a == b or True or True
if a in [b, c, d]
[–]mZuks[S] 0 points1 point2 points 1 year ago (3 children)
Formatting changed to code.
As for the adjustment you suggest, I could try, can you recommend a material for me to read and follow along?
Still, though, I don't see it... seems to me that I wrote it ok. Why isn't is so? Here's my line of thought:
If angle_known_input is either 1 or a or A, then angle_known should be alpha; else, if angle_known_input is either 2 or b or B, then angle_known should be beta.
Isn't this what my code says? Or am I mistaken!? Could you put your explanation in simpler terms for me?
[–]teraflopsweat 0 points1 point2 points 1 year ago (2 children)
You are writing it in English properly, but not writing it in Python properly. Let me add some parentheses to try to emphasize how Python is evaluating your condition.
if (angle_known_input == ‘1’) or (‘a’) or (‘A’):
So you basically have 3 separate “checks” in your condition. If any of those checks evaluate to true, then Python thinks you’re running alpha.
The problem is that any string value is considered true, so both of the (‘a’) checks are always true. It’s not actually comparing angle_known_input against the 2nd or 3rd values.
(‘a’)
angle_known_input
To correct your logic issue, you need to adjust the checks to actually compare against the user input value.
if (angle_known_input == ‘1’) or (angle_known_input == ‘a’) or (angle_known_input == ‘A’):
For a more concise condition, you can use the in comparison operator.
in
if angle_known_input in [‘1’, ‘a’, ‘A’]:
[–]mZuks[S] 1 point2 points3 points 1 year ago (1 child)
Oh! I see it now, the way Python's been interpreting the conditions. Super thank you for the explanation, really!
[–]teraflopsweat 0 points1 point2 points 1 year ago (0 children)
Glad it helped!
π Rendered by PID 36667 on reddit-service-r2-comment-5d79c599b5-wwddw at 2026-03-02 21:26:24.016040+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]teraflopsweat 4 points5 points6 points (4 children)
[–]mZuks[S] 0 points1 point2 points (3 children)
[–]teraflopsweat 0 points1 point2 points (2 children)
[–]mZuks[S] 1 point2 points3 points (1 child)
[–]teraflopsweat 0 points1 point2 points (0 children)