7 Answers
+ 2
A condition after the 'if' is evaluated either as 'True' or 'False'. The keyword True itself though will always be 'True'.
The first condition is like: 'If True is not true...' And since that can never be the case, the code moves on to check for the elif.
(Is the rest of the code clear?)
+ 4
this prints 2 because "not True" equates to false, "not(1+1==3)" equates to "not(False)" which is true and the else doesn't execute as one of the other conditions was met
+ 3
hinanawi has already answered your questions, but I think it's can be helpful.
https://code.sololearn.com/cy0t3518QBDv/?ref=app
+ 2
It is the same as thisďź
if False:
print("1")
elif True:
print("2")
else:
print("3")
+ 1
i have rewritten the code for simple understanding
#the following if returns 'False' as not of 'True' is 'False'
if not(True):
print("1")
#The following Line returns 'True' as (2==3) returns 'False' and not('False' ) is 'True'
elif not(1+1==3):
print("2")
else:
print("3")
Hence the answer is 2
+ 1
Basically yes, bobo.
Normally you would have some expression that still has to be evaluated as True or False, like:
if type(x) != float:
print('Enter a number I said!!)
But you can also go with the result directly, like when you want to create an eternal loop:
while True:
print('a cat is', end =' ')
+ 1
In the code three conditions are used with if, elif and else statement.
At Step1-- code will go in the if loop and check for the logic. here condition is if true is not true i.e. true is false, then print 1. But True cannot be equal to False, so this condition does not satisfied and this step is skipped. code further check condition in step2
Step2-- Code check if not 1+1 == 3, which is true. hence it will execute elif part and print 2 as result.
Hope this will answer your question.