+ 2

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

18th Jul 2019, 8:12 PM
Deprion
Deprion - avatar
6 Respuestas
0
Solved this problem through "is not" and replacing "or" on "and"
19th Jul 2019, 10:23 AM
Deprion
Deprion - avatar
+ 5
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":
18th Jul 2019, 8:16 PM
Faisal
Faisal - avatar
+ 1
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
18th Jul 2019, 8:57 PM
ChrA
ChrA - avatar
+ 1
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)
22nd Jul 2019, 8:24 PM
Anil
0
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
19th Jul 2019, 5:59 AM
ChrA
ChrA - avatar