1

I'm trying to get the user input and check whether it has 'heads' or 'tails' in it using if statement. But I end up getting the same output.

user_input = input('Heads? or Tails? \n')

if 'HEADS' or 'TAILS' in user_input.upper():
    print ('you have chosen', user_input)
else:
    print ('wrong!')

Input:

random text

Expected output:

wrong!

Output that I get:

you have chosen random text
1
  • Even though this is a simple and common misconception, given that you asked it in a good way (with MCVE provided), I go +1 for this Commented Dec 25, 2018 at 2:21

2 Answers 2

2

or does not work that way

if 'HEADS' in user_input.upper() or 'TAILS' in user_input.upper():
Sign up to request clarification or add additional context in comments.

Comments

0

When using the OR operator, you have to treat the latter expression as it's own condition to satisfy:

if "HEADS" in user_input.upper() or "TAILS" in user_input.upper():
  print("you have chosen", user_input)
else:
  print("wrong")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.