0
not working when compared to string
a="Mayilesh" if a=="Mayilesh": print("correct ") else: print(" wrong") why it is not working
8 Answers
+ 2
Forgot blanks between variables?
a = "sum"
if a == "sum":
print('yes')
else:
print ('no')
Tested, works
+ 1
thank you
0
Thw space between the two variables.
Correct code:
a = "Mayilesh"
if a =="Mayilesh":
print("correct ")
else:
print(" wrong ")
0
u can also try to compare by using string length
so that it is easily comparable
0
Your code is correct. I don't know why you got the wrong answer. Some people are saying you need space I between the variables but you don't. Space or no space makes no difference.
I thought it may have been a playground bug but I tested it there and it worked fine.
There is nothing visibly or functionally wrong with the code you posted.
0
of course the problem is the space.
a=thing it isn't a = thing.
0
Spaces are not required. Who fed you this misinformation?
0
You need to remember that the "=" is assigning your string to a variable(in this case, it is "a"), instead of comparing the string to the left side of the "=". To compare two values or strings, you must use "==" instead of "=". Sorry if this is confusing or if I misunderstood your question.