Comparision of one value with multiple values

Submitted 3 years, 7 months ago
Ticket #153
Views 212
Language/Framework Python
Priority Medium
Status Closed

I want a code which compares multiple integer values for one value and therefore it returns a list as an output with the appended values 

FOR EXAMPLE:

​
x = 10
y = 11
z = 13
mylist = []

if x or y or z == 10 :
    mylist.append("C")
if x or y or z == 11 :
    mylist.append("C++")
if x or y or z == 2 :
    mylist.append("JAVA")
if x or y or z == 13 : 
    mylist.append("PYTHON")

​

if we take like this

finally it should return a list like

["C","C++","PYTHON"]

Submitted on Sep 10, 20
add a comment

1 Answer

x = 0
y = 1
z = 3
mylist = []
if 0 in (x,y,z):
    mylist.append("C")
if 1 in (x,y,z):
    mylist.append("C++")    
if 2 in (x,y,z):
    mylist.append("java")    
if 3 in (x,z):
    mylist.append("py")
print(mylist)

it will give

['C', 'C++', 'py']

Submitted 3 years, 7 months ago


Latest Blogs