+ 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
7 Answers
+ 2
What was the error that you got?
+ 2
Did you indent the print function within the if statement?
+ 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)
+ 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!
+ 1
It still shows error When I used your code.
+ 1
intented block erroe
+ 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)