Python Selection Statements
Python Selection Statements
If(age<0):
Print(“You entered Negative Number”)
Syntax:
if ( condition):
…………………..
else:
…………………..
Flowchart
Example-1:
Age=int(input(“Enter Age: “))
if ( age>=18):
print(“You are eligible for vote”)
else:
Example-2:
N=int(input(“Enter Number: “))
if(n%2==0):
print(N,“ is Even Number”)
Else:
print(N,“ is Odd Number”)
Python Ladder if else statements (if-elif-else)
This construct of python program consist of more than one if condition.
When first condition evaluates result as true then executes the block
given below it. If condition evaluates result as false, it transfer the
control at else part to test another condition. So, it is multi-decision
making construct.
Syntax:
if ( condition-1):
…………………..
…………………..
elif (condition-2):
…………………..
…………………..
elif (condition-3):
…………………..
…………………..
else:
…………………..
…………………..
Example:
num=int(input(“Enter Number: “))
If ( num>=0):
Print(“You entered positive number”)
elif ( num<0):
Print(“You entered Negative number”)
else:
Print(“You entered Zero ”)
Python Nested if statements
It is the construct where one if condition take part inside of other if
condition. This construct consist of more than one if condition. Block
executes when condition becomes false and next condition evaluates
when first condition became true.
So, it is also multi-decision making construct.
Syntax: FlowChart
if ( condition-1):
if (condition-2):
……………
……………
else:
……………
……………
else:
…………………..
…………………..
Example:
num=int(input(“Enter Number: “))
If ( num<=0):
if ( num<0):
Print(“You entered Negative number”)
else:
Print(“You entered Zero ”)
else:
Print(“You entered Positive number”)
Program: find largest number out of given three numbers
x=int(input("Enter First Number: "))
y=int(input("Enter Second Number: "))
z=int(input("Enter Third Number: "))
if(x>y and x>z):
largest=x
elif(y>x and y>z):
largest=y
elif(z>x and z>y):
largest=z
print("Larest Value in %d, %d and %d is: %d"%(x,y,z,largest))
1. Loan Amount: Input the desired loan amount that you wish to
avail.
2. Loan Tenure (In Years): Input the desired loan term for which you
wish to avail the loan.
3. Interest Rate (% P.A.): Input interest rate.
4. EMI=[ [P*R*(1+R)N] / [(1+R)N-1] ]