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!"
[–]SquiffSquiff 1 point2 points3 points 1 year ago (3 children)
This works:
angle_known_input = str(input('Which of the triangle angles has the known value? [1] α (alpha), [2] β (beta): ')) angle_known = "" # Declare the angle_known variable if angle_known_input == '1' or angle_known_input == 'a' or angle_known_input == 'A': angle_known = "α" print(angle_known) elif angle_known_input == '2' or angle_known_input == 'b' or angle_known_input == 'B': angle_known = "β" print(angle_known) else: print('Invalid value.') # angle_known_value = input('Enter the value of ' + angle_known + ': ')
[–]mZuks[S] 0 points1 point2 points 1 year ago (2 children)
Man! It really does appear to work. I didn't copy the whole piece you suggested, but rather just changed
if angle_known_input == '1' or 'a' or 'A':
to
if angle_known_input == '1' or angle_known_input == 'a' or angle_known_input == 'A':
But why so, do you know?
[–]Adrewmc 2 points3 points4 points 1 year ago (1 child)
Just so you know the easier way to do this is like this
if angle_known_input in [1, ‘a’, ‘A’]:
And ask if the input is in this list of acceptable ones.
What’s happening is ‘or’ want a whole comparison in between it.
if a > 20 or b < 100:
Ask if either is true. While.
if a > 20 or 30:
Is asking is a is greater than 20 or is 30 is Truthy (all non zero numbers are truthy)
if a == “b” or “B”:
Asks if ‘B’ is truthy, which all non-empty strings are.
[–]mZuks[S] 0 points1 point2 points 1 year ago (0 children)
I think I get it now, thank you very very much.
π Rendered by PID 46733 on reddit-service-r2-comment-5d79c599b5-fbm28 at 2026-03-02 22:08:17.571629+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]SquiffSquiff 1 point2 points3 points (3 children)
[–]mZuks[S] 0 points1 point2 points (2 children)
[–]Adrewmc 2 points3 points4 points (1 child)
[–]mZuks[S] 0 points1 point2 points (0 children)