if statement in python with suitable diagram & Examples


 Introduction: 

The if statement is the simplest form. It takes a condition and evaluates it to either True or False.If the condition is True, then the True block of code will be executed, and if the condition is False, then the block of code is skipped, and The controller moves to the next line



Examples:

Examples1:
  • a=10
  • b=20
  • if a<b:
  • print("yes a is less then b",'A=',a,'B=',b)
In this example, you can just be checking two values which one is bigger as you can execute it is given online compiler.

Examples2:

  •  a=input("please enter any number")
  •  b=input("please enter any number")
  •  if a==b:
  •  print("yes a==b")
  •  print(a,b)
In this example, you will be tacking as input from the user and checking through if condition which one is satisfied the condition if a==b then print yes execute this code with given online compiler.


Examples3:
  • a=input("please tell your mobile bettery %")
  •  if int(a)>=80:
  • print("The your cell is charged 80% ")
In this example, we implement the operators in if the condition and let create a condition
 

Post a Comment

0 Comments