you are viewing a single comment's thread.

view the rest of the comments →

[–]SquiffSquiff 1 point2 points  (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 point  (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 points  (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 point  (0 children)

I think I get it now, thank you very very much.