Condition Using If
Condition Using If
STATEMENTS
Learning Outcomes
Compound_Statement_Header :
indented_body containing multiple
simple or compoundstatement
Compound Statement has:
Statement 1
Statement 2
Selection :Itmeans executionofstatement will depend uponthecondition.If
the condition is true then it will execute Action 1 otherwise Action 2. In Python we
use if to perform selection
Action 1
True
Condition ? Statement 1 Statement 2
False
Statement 1
Action 2
Statement 2
Selection
False
Condition ? Exit from iteration
True
Statement 1
Loop Body
Python supports for and
Action 2
bonus =0
sale = int(input("Enter Monthly Sales :"))
if sale>50000:
bonus=sale * 10 /100
print("Bonus = " + str(bonus))
1.WAPto enter2numberandprintthelargestnumber
2.WAPto enter3numberandprintthe largestnumber
1.WAPto enter2numberandprintthelargestnumber
import math
print("For quadratic equation, ax**2 + bx + c = 0,
enter coefficients ")
a = int(input("enter a"))
b = int(input("enter b"))
c = int(input("enter c"))
if a==0:
print("Value of ",a," should not be zero")
print("Aborting!!!")
else:
delta = b*b - 4 *a * c
Program to calculate and print roots of a quadratic equation:
ax2+bx+c=0(a!=0)
if delta>0:
root1=(-b+math.sqrt(delta))/(2*a)
root2=(-b-math.sqrt(delta))/(2*a)
print("Roots are Real and UnEqual")
print("Root1=",root1,"Root2=",root2)
elif delta==0:
root1=-b/(2*a)
print("Roots are Real and Equal")
print("Root1=",root1,"Root2=",root1)
else:
print("Roots are Complexand
Imaginary")
To Do…
1. WAP to enter marks of 5 subject and calculate total, percentage
and also division.
Percentage Division
>=60 First
>=45 Second
>=33 Third
otherwise Failed
2. WAP to enter any number and check it is positive, negative or zero
number
3.WAP to enter Total Bill amount and calculate discount as per given
table and also calculate Net payable amount (total bill – discount)
Total Bill Discount
>=20000 15% ofTotal Bill
>=15000 10% ofTotal Bill
>=10000 5% of Total Bill
otherwise 0 ofTotal Bill
To Do…
4. WAP to enter Bill amount and ask the user the payment
mode and give the discount based on payment mode. Also
display net payableamount
Mode Discount
Credit Card 10% of billamount
Debit Card 5% of bill amount
Net Banking 2% of bill amount
otherwise 0
5.WAP to enter two number and ask the operator (+ - * / )
from the user and display the result by applying operator on
the two number
6. WAPto enter any character and print it is Upper Case,
Lower Case, Digit or symbol
7.WAPto enter 3number and print the largest number
8.WAP to input day number and print corresponding day
name for e.g if input is 1output should be SUNDAYand so on.
Nested i f
▪ In this type of “if” we put if within another if as a
statement of it. Mostly used in a situation where we
want different else for each condition. Syntax:
if condition1:
if condition2:
statements
else:
statements
elif condition3:
statements
else:
statements
WAPtocheckentered year is leapyear or not