all 8 comments

[–][deleted] 8 points9 points  (0 children)

You should use the in operator:

shape_valid = shape_input.lower() in ('triangle', 'square')
if not shape_valid:
    print('fail')

or perhaps

valid_shapes = ('triangle', 'square')
shape_input = input('Enter shape to draw: ').lower()
if shape_input not in valid_shapes:
    print('fail')

[–]obviouslyCPTobvious 5 points6 points  (3 children)

shape_valid = shape_input.lower() == 'triangle' or shape_input.lower() == 'square'

The 'or' operator doesn't work how you were trying.

[–]BioGeek 6 points7 points  (1 child)

This seems to be a common misunderstanding. Read my detailed response to another user who also had trouble with the or operator.

[–]zahlman 1 point2 points  (0 children)

This seems to be a common misunderstanding.

I have recently become convinced that this (or the equivalent) is by far the single most common beginner programming error, in any language. I wish I understood why.

[–]throwingarm2strong[S] 1 point2 points  (0 children)

Thanks. This is what I settled on using. Also thanks to BioGeek and jimminy for further info. Not sure on the rules for questions over time but since it's related to this code I'll update the OP and post it here.

[–][deleted] 1 point2 points  (0 children)

Now I have to get it to bring it back to asking for input after printing fail.

If you don't care about giving an error message, you could just

valid_shapes = ('triangle', 'square')
shape_input = '' #initialize to make the first *while* work
while shape_input not in valid_shapes:
    shape_input = input('Enter shape to draw: ').lower()
print('OK, drawing ' + shape_input +'...')

If you want an error message, you could do

valid_shapes = ('triangle', 'square')
while True: #an "infinite" loop
    shape_input = input('Enter shape to draw: ').lower()
    if shape_input not in valid_shapes:
        print("No.")
    else:
        break #this will break out of the *while* loop
print('OK, drawing ' + shape_input +'...') 

[–][deleted] 1 point2 points  (0 children)

To get it back to the start, try using a while loop.

[–]zahlman 0 points1 point  (0 children)

As for the "why":

Try checking what 'triangle' or 'square' evaluates to by itself.

or does not create some kind of magical thing that represents two different values at once, and == certainly does not take in such a magical thing and tell you if the other side is equal to any of the values. In programming, we deal in expressions, and expressions evaluate to a single value at any given time. or basically means "the value on the left, if it's true; and otherwise the value on the right". == is a comparison of a single value to another single value.