+ 1

Boolean Logic Python Its Easy for You.

if(1 == 1) and (2 == 2): print ("Hello") print(1 == 1 and 2 == 3) print(1 != 1 and 2 == 2) print(2 < 1 and 3 > 6) What I am doing wrong in this code? please help

25th Feb 2018, 3:28 PM
Robin
Robin - avatar
7 Answers
+ 2
What was the error that you got?
25th Feb 2018, 3:48 PM
Faisal
Faisal - avatar
+ 2
Did you indent the print function within the if statement?
25th Feb 2018, 3:49 PM
Faisal
Faisal - avatar
+ 2
#Here, it should be this: if 1 == 1 and 2 == 2: print("True") print(1 == 1 and 2 == 3) print(1 != 1 and 2 == 2) print(2 < 1 and 3 > 6)
25th Feb 2018, 3:56 PM
Faisal
Faisal - avatar
+ 1
Well first, in Python, brackets in if statement don't need to be there as they will result in a syntax error. It may look a little weird when you first start, but you get used to it as time goes by. Second, any statements within an if block must be indented, as Python doesn't use curly brackets at all. This just specifies that they should be run if the condition in the if statement evaluates to true. Your code should then look like this: if 1 == 1 and 2 == 2: print("Hello") #The rest should be fine Hope this helped!
25th Feb 2018, 3:37 PM
Faisal
Faisal - avatar
+ 1
It still shows error When I used your code.
25th Feb 2018, 3:46 PM
Robin
Robin - avatar
+ 1
intented block erroe
25th Feb 2018, 3:48 PM
Robin
Robin - avatar
+ 1
if 1 == 1 and 2 == 2: print("True") print(1 == 1 and 2 == 3) print(1 != 1 and 2 == 2) print(2 < 1 and 3 > 6)
25th Feb 2018, 3:54 PM
Robin
Robin - avatar