If and two statements str

I want what when i use 'or' "if" work properly with one and another str, but he don't work properly, how i understand. Do u can explain me my mistake and give me right code in this situation? https://code.sololearn.com/cksohkZ6W4Vr/?ref=app

7/18/2019 8:12:47 PM


9 Answers

New Answer


Solved this problem through "is not" and replacing "or" on "and"


Because Python is case sensitive, the if statement should be written with an if rather than If. Additionally, the condition seems to be a little off, so changing it to the following should allow it to run: if Item == "var1" or Item == "var2":


1. I don't think you need this () 2. Try.. Print(lucky+10 if Item == "var1" or Item == "var2" else "")


Deprion For checking a variable against multiple values you can also use the 'in'. Try if Item in ("var1", "var2"): .... Hope that helps. Cheers. C


Here in this case use two separate print statements if we assign var1 or var2 for variable "Item" it will print 30 else prints 20. And Python is case sensitive here "if" is conditional keyword should always be in lower case, Item = "var1" Lucky = 20 if Item == "var1" or Item == "var2": Lucky += 10 print(Lucky) else: print(Lucky)


I believe the problem initially is in the comparison of "var1" or "var2" What I am understanding you want to do is check if Item wether is "var1" or Item is "var2", what is differently by noted down. Either as Faisal described it or the way I mentioned. Cbr✔[ Not Active ] your example is very compact but might be hard to read. Cheers. C


Btw, in sololearn code don't work at all. So, i tested this code in PyCharm...


Cbr✔[ Not Active ] Does not work


Faisal It's not work properly