0

not working when compared to string

a="Mayilesh" if a=="Mayilesh": print("correct ") else: print(" wrong") why it is not working

23rd Jul 2016, 11:52 AM
Mayil esh
Mayil esh - avatar
8 Answers
+ 2
Forgot blanks between variables? a = "sum" if a == "sum": print('yes') else: print ('no') Tested, works
23rd Jul 2016, 12:00 PM
Andreas Kilian
Andreas Kilian - avatar
+ 1
thank you
23rd Jul 2016, 12:38 PM
Mayil esh
Mayil esh - avatar
0
Thw space between the two variables. Correct code: a = "Mayilesh" if a =="Mayilesh": print("correct ") else: print(" wrong ")
23rd Jul 2016, 12:45 PM
Abel Fernando Barros Rodrigues
Abel Fernando Barros Rodrigues - avatar
0
u can also try to compare by using string length so that it is easily comparable
23rd Jul 2016, 1:11 PM
kesavamurthy k
kesavamurthy k - avatar
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.
23rd Jul 2016, 2:43 PM
Gershon Fosu
Gershon Fosu - avatar
0
of course the problem is the space. a=thing it isn't a = thing.
23rd Jul 2016, 2:51 PM
Abel Fernando Barros Rodrigues
Abel Fernando Barros Rodrigues - avatar
0
Spaces are not required. Who fed you this misinformation?
23rd Jul 2016, 3:10 PM
Gershon Fosu
Gershon Fosu - avatar
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.
30th Aug 2016, 1:41 PM
Hunter
Hunter - avatar