CLASS IX IF AND ELSE conditions



 Python supports the usual logical conditions from mathematics:

  • Equals: a == b
  • Not Equals: a != b
  • Less than: a < b
  • Less than or equal to: a <= b
  • Greater than: a > b
  • Greater than or equal to: a >= b

These conditions can be used in several ways, most commonly in "if statements" and loops.

An "if statement" is written by using the  if keyword.

PROGRAM 1

a = 33
b = 200
if b > a:
  print("b is greater than a")

PROGRAM 2

a = 33
b = 33
if b > a:
   print("b is greater than a")
elif a == b:
  print("a and b are equal")


PROGRAM 3

a = 200
b = 33
if b > a:
  print("b is greater than a")
elif a == b:
  print("a and b are equal")
else:
  print("a is greater than b")


PROGRAM 4

a = 200
b = 33
if b > a:
  print("b is greater than a")
else:
  print("b is not greater than a")







Post a Comment

0 Comments