Why cant i run this code in playground? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Why cant i run this code in playground?

a = 2 b = 2 if a=b: print ("True ")

21st Feb 2016, 6:04 AM
Prabin Parajuli
Prabin Parajuli - avatar
4 Antworten
+ 4
because you are using only one equal sign (" = ") when you wrote the if statement "a=b" when you should be using two ("a ==b") to compare the values. "a = b" is identifying "a" as "b" (with the single "=" ) not comparing the two values as you originally intended. the correct code would have "if a == b" not "a = b" "if a == b" : it would compare the values between the two variables, and if the value of "a" is equal to the value of "b" it will prove "True" , satisfying the "if" statement and run any code indented beneath it. "if a=b" is saying if "a=b" , and "a=b" is just identifying "a" as "b" , not using any Boolean logic to compare values and return with a "True" or "False" (which is needed to satisfy the "if" statement and execute any code underneath it.) Hope I helped and explained that clearly enough. Anyone please feel free to correct or re-explain anything Ive just said as I've only started learning the first of anything on this app a few days ago.
27th Feb 2016, 7:10 PM
Robert M
Robert M - avatar
+ 4
Don't confuse assignment ("=") with comparison ("==").
25th Jun 2016, 10:43 AM
Deybith
+ 3
you should use the '==' sign.Dont get confused with a comparison & an assignment
28th Jun 2016, 2:22 AM
Koustav Goswami
+ 2
it's about comparison .so you should use '==' sign.
30th Jun 2016, 2:44 AM
pragati das
pragati das - avatar