is there any option to compare a variable with number and a string in a same if statement using or oprator?
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3
--
Chapters
00:00 Is There Any Option To Compare A Variable With Number And A String In A Same If Statement Using Or O
00:21 Accepted Answer Score 5
00:51 Answer 2 Score 1
01:14 Answer 3 Score 1
01:30 Answer 4 Score 0
01:42 Thank you
--
Full question
https://stackoverflow.com/questions/5698...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python
#avk47
ACCEPTED ANSWER
Score 5
input returns a string, so you need to compare with the strings.
Also, you can use in (__contains__) to check for a value in a given collection that implements __contains__ (could be any primitive collection e.g. tuple, list, set, but using set would be efficient due to the O(1) lookups, but the cost of creating the collection would be the same for all):
if x in {'1', 'yes'}:
You can obviously do this using the or-chain, but that won't be as readable and maintain-able as using a collection.
ANSWER 2
Score 1
You can try this:
print("enter you choice either 1 for yes\n 2 for no")
x=input("enter your choice")
if(x in {1, '1', 'yes'}):
     x=5
elif(x in {2, '2', 'yes'}):
      x=6
print(x)
Python input always returns a string in python3. If you are using python2 it could have returned integers. If you simply check for 1 or '1' (since for the user they mean the same) it will work on both versions of python
ANSWER 3
Score 1
The input() function returns a string. So in your case, although the user would input 1 or 2, x would still be a string '1' or '2'. So what you could do is 
if x in ['1', 'yes']:
   # do something
elif x in ['2', 'no']:
   # do something else
ANSWER 4
Score 0
I have updated your code and this is the result, the problem was you was comparing a str and int, to fix it you just had to do this.
if (x == "1") or (x == "yes")
#code
elif (x == "2") or (x == "no")