+ 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
5 Answers
0
Solved this problem through "is not" and replacing "or" on "and"
+ 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":
+ 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
+ 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)
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