If and not if question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

If and not if question

I want to know if I can ever get this first line to be excuted and why is it not. Please explain thanks If not true: Print("1") Elif (1+1==3): Print("2") Else: Print("3") Here which statement is the first pointing to. And this is shown as error. I expected since the whole statement is gonna be false and the second statement doesn't run the first should run and the output will result in printing 1 but that is not the case. Can somebody explain how this works? Thanks

22nd Apr 2021, 5:53 AM
Jithu George
Jithu George - avatar
4 Answers
0
there’s an error because you have used capital letters wrong. now it should work: if not True: print("1") elif (1+1==3): print("2") else: print("3")
22nd Apr 2021, 6:39 AM
Olga
Olga - avatar
0
Ok, first of all "E" in "Elif" & "Else" should be "IN LOWER CASE" is "elif" & "else". Now, In your code first "if" statement will be always "false" because its "not true". Then it will come to your "elif" statement, which is also false as (1+1 == 3) will return "false". Then your "else" statement will be executed. so it will print 3.
22nd Apr 2021, 6:41 AM
Priyanshu Kumar
Priyanshu Kumar - avatar
0
So there's no way to make the output print 1?
22nd Apr 2021, 8:22 AM
Jithu George
Jithu George - avatar
0
No with "not true" its not possible For that it should be "true" or "not false". "not true" will alway return "false" Therefore if statement will not be executed.
22nd Apr 2021, 2:59 PM
Priyanshu Kumar
Priyanshu Kumar - avatar