Dear Students, if-elif-else python exercises Class11 provides you the practical list of python programs for annual exam practical records.

## if-elif-else python exercises Class11

 The given number is odd or even.

``````def odd_even():
n = int(input("Enter any number:"))
if n % 2!=0:
print("No is odd")
else:
print("No is even")
odd_even()``````

 The given number is positive or negative or zero.

``````def pnz_check():
n = int(input("Enter any number:"))
if n>0:
print("No is positive")
elif n<0:
print("No is negative")
else:
print("Zero")
pnz_check()
``````

 The given number is of one digited or two digited or three digited or more than three digited.

``````def dig_check():
n = int(input("Enter any number:"))
if n>0 and n<10:
print("One digit number")
elif n>10 and n<100:
print("Two digit number")
elif n>100 and n<1000:
print("Three digit number")
else:
print("More than three digit number")
dig_check()
``````

 The entered number is smallest 4 digit number or not.

``````def smallest4digit():
n = int(input("Enter any number:"))
if n==1000:
print("n is smallest 4 digit no")
else:
print("n is not a smallest 4 digit no")
smallest4digit()``````

 The given character is an uppercase letter or lowercase letter or a digit or a special character.

``````def check_chr():
ch = input("Enter a character to check:")
if ord(ch)>=65 and ord(ch)<=90:
print("The character", ch, "  is an uppercase letter")
elif ord(ch)>=97 and ord(ch)<=122:
print("The character", ch, "  is a lowercase letter")
elif ord(ch)>=48 and ord(ch)<=57:
print("The character", ch, "  is a digit")
else:
print("The character", ch, "  is a special chacracter")
check_chr()
``````

 The given year is a leap year or not.

``````def check_leapyear():
year = int(input("Enter a character to check:"))
if (year%4==0 and year%100!=0) or (year%400==0):
print("Year is a leap year")
else:
print("Year is not a leap year")
check_leapyear()``````

 The given number is divisible by 5 or not.

``````def check_div5():
n = int(input("Enter a number to check:"))
if n%5==0:
print("No is divisible by 5")
else:
print("No is not divisible by 5")
check_div5()``````

 Find maximum number out of given three numbers.

``````def check_max3():
n1,n2,n3 = int(input("Enter no1:")),int(input("Enter no2:")),int(input("Enter no3:"))
if n1>n2 and n1>n3:
print("No1 is maximum")
elif n2>n1 and n2>n3:
print("No2 is maximum")
elif n3>n1 and n3>n2:
print("No3 is maximum")
else:
print("All are equal")
check_max3()``````

 Find minimum number out of given three numbers.

Do it yourself.

Watch this video lesson explains the programms.

 Write a program that reads three positive numbers a, b, c and determines whether they can form the three sides of a triangle.

``````def check_3tri():
a=int(input("Enter no1:"))
b=int(input("Enter no2:"))
c=int(input("Enter no3:"))
if(((a+b)<=c)or((b+c)<=a)or((c+a)<=b)):
print("It can not form the triangle")
else:
print("It can form the triangle")
check_3tri()``````

 Whether the triangle will be an obtuse-angle, or a right-angle or an acute-angle triangle.

``````def check_tritype():
a=int(input("Enter no1:"))
b=int(input("Enter no2:"))
c=int(input("Enter no3:"))
square_a = a**2
square_b = b**2
square_c = c**2
if square_a == square_a + square_b or square_b == square_a + square_c or square_c == square_a + square_b:
print("Right-angled Triangle")
elif square_a > square_c + square_b or square_b > square_a + square_c or square_c > square_a + square_b:
print("Obtuse-angled Triangle")
else:
print("Acute-angled Triangle")
check_tritype()
``````

 If the triangle is an acute angle triangle, determine further whether the triangle is equilateral, isosceles, or scalene.

``````def check_tritype2():
a=int(input("Enter no1:"))
b=int(input("Enter no2:"))
c=int(input("Enter no3:"))
if a==b==c:
print("Equilateral triangle")
elif a==b or b==c or c==a:
print("isosceles triangle")
else:
print("Scalene triangle")
check_tritype2()``````

 A toy vendor supplies three types of toys: Battery Based Toys, Key-based Toys, and Electrical Charging Based Toys. The vendor gives a discount of 10% on orders for battery-based toys if the order is for more than Rs. 1000. On orders of more than Rs. 100 for key-based toys, a discount of 5% is given, and a discount of 10% is given on orders for electrical charging based toys of value more than Rs. 500. Assume that the numeric codes 1,2 and 3 are used for battery based toys, key-based toys, and electrical charging based toys respectively. Write a program that reads the product code and the order amount and prints out the net amount that the customer is required to pay after the discount.

``````def compute_discount():
print("1. For Battery based Toys")
print("2. For Key based Toys")
print("3. Electric chargin based Toys")
opt = int(input("Enter the product code (1,2 or 3)?:"))
amt = int(input("Enter the amount:"))
if opt==1:
if amt>1000:
dis = amt * 0.1
else:
dis = 0
elif opt==2:
if amt>100:
dis = amt * 0.05
else:
dis=0
elif opt==3:
if amt>500:
dis = amt*0.1
else:
dis = 0
else:
print("Product is not available")
bill_amt= amt - dis
print("Customer has to pay:",bill_amt)
compute_discount()
``````

  A function f is defined as follows :

f(x)   =    ax3 – bx2 + cx –d,                  if x > k

=    0,                                             if x = k

=    -ax3 + bx2 – cx +d,                 if x < k

Write a program that reads a, b, c, d, k and x and prints the value of f(x).

``````def sol14():
a = int(input("Enter a:"))
b = int(input("Enter b:"))
c = int(input("Enter c:"))
d = int(input("Enter d:"))
k = int(input("Enter k:"))
x = int(input("Enter x:"))
if x > k:
fx = a*(x**3) - b*(x**2) + c*x -d
if x ==k:
fx =0
if x < k:
fx =  -a*(x**3) + b**x**2) - c*x + d
print(fx)
sol14()``````

 Write a program to do the following operations :

• Read any two positive integer numbers (say n1 & n2) and one character type operator (say opr). Note that opr is any mathematical operator.
• Depending upon the operator, do the appropriate operation. e. g. if opr is ‘+’ then the display the value obtained by evaluating the expression (n1 + n2).
``````def sol15():
n1 = int(input("Enter n1:"))
n2 = int(input("Enter n2:"))
print("\ for division\n")
ch = input("Enter the choice:")
if ch=='+':
ans = n1 + n2
elif ch == '-':
ans = n1 - n2
elif ch == '*':
ans = n1 * n2
elif ch == '/':
ans = n1 / n2
else:
print("Invalid choice")
sol15()``````

Below you will find the list of application based program list for if-elif-else python exercises Class11.

 The Paschim Gujarat Vij Company Ltd. computes the electricity bill based on the following matrix:

2. Find the units consumed.
3. Compute the bill according to given matrix.
``````def sol16():
pmr = int(input("Enter past meter reading:"))
cmr = int(input("Enter current meter reading:"))
uc = cmr - pmr
if uc>0 and uc<=100:
bill_amt = uc * 0.50
elif uc>100 and uc<=200:
bill_amt = 50 + (uc-100) * 1
elif uc>200 and uc<=300:
bill_amt = 150 + (uc-200) * 1.50
else:
bill_amt = 300 + (uc-300) * 2
print("The bill amount is:",bill_amt)
sol16()``````

 A cloth showroom has announced the following discounts on the purchase of specific items :

1. Ask user to enter the amount and assign following code for the items such as sh for shorts, p for pans and sht for shirts/t-shirts.
2. Compute the discount and net amount paid by customer.
``````def sol17():
print("/'sh/' for Short")
print("/'p/' for Pants")
print("/'t/' for t-shirts")
opt = input("Enter the product code (/'sh/',/'p/',/'sht/')?:"))
amt = int(input("Enter the amount:"))
if opt=='s' opt=='S':
if amt>0 and amt<100:
dis = 0
elif amt>100 and amt<200:
dis = amt * 0.05
elif amt>201 and amt<300:
dis = amt * 0.1
else:
dis = amt * 0.18
elif opt=='p' opt=='P':
if amt>0 and amt<100:
dis = amt * 0.03
elif amt>100 and amt<200:
dis = amt * 0.08
elif amt>201 and amt<300:
dis = amt * 0.12
else:
dis = amt * 0.20
if opt=='t' opt=='T':
if amt>0 and amt<100:
dis = amt * 0.05
elif amt>100 and amt<200:
dis = amt * 0.10
elif amt>201 and amt<300:
dis = amt * 0.15
else:
dis = amt * 0.22
bill_amt = amt - dis
print("Customer has to pay:",bill_amt)
sol17()
``````

 BSNL has three categories of customers: Industrial, Bulk Institutional and Domestic. The rates for these are tabulated below :

1. Ask user to enter customer category, Units.
2. Compute the bill as per given criteria.
3. Print bill in proper format.
``````def sol18():
cat = input("Enter the category(commerical, institutional, or domestic:")
units =int( input("Enter the units:"))
if cat == "commercial":
if units>0 and units<=5000:
bill = 1500
elif units>5000 and units<=10000:
bill = units * 0.25
elif units>10000 and units<=15000:
bill = units * 0.23
elif units>15000:
bill = units * 0.20
elif cat == "institutional":
if units>0 and units<=5000:
bill = 1800
elif units>5000 and units<=10000:
bill = units * 0.30
elif units>10000 and units<=15000:
bill = units * 0.28
elif units>15000:
bill = units * 0.25
if cat == "domestic":
if units>0 and units<=100:
bill = 75
elif units>100 and units<=200:
bill = units * 1.25
elif units>200and units<=300:
bill = units * 2
elif units>300:
bill = units * 2.50
print("*"*80)
print("The category:",cat)
print("Units:", units)
print("*"*80)
print("Bill amount:", bill)
sol18()
``````

 A transport company charges the fare according to following table:

Ask user to enter the distance and compute the fare.

``````def sol19():
distance = int(input("Enter distance:"))
if distance>=1 and distance<=50:
fare = distance * 8
elif distance>=51 and distance<=100:
fare = distance * 10
elif distance>100:
fare = distance * 12
else:
print("Invalid fare")
print("The total fare is:",fare)
sol19()
``````

 The Sardar Patel Cricket Stadium, Motera has the following rates for different types of seats:

1. Ordinary – 2500
2. Pavillion – 3500
3. Upper Pavillion – 4500
4. Commentary Box – 6000
5. VIP – 8000

They are giving 10% discount for online booking and 8% discount for advance booking and no discount is given for booking on match day from ticket window.

1. Ask user to enter the booking type like online, advance or window booking.
2. Ask user to select the types of seats.
3. Compute the amount and print the ticket with proper format.
``````def sol20():
b_type = input("Enter booking type(online or advanced or window):")
s_type = input("Enter seat type(ordinary,pavallion,upper pavallion, commentary box,VIP):")
nop = int(input("Enter no. of persons:"))
if s_type=="ordinary":
rate = 2500
elif s_type=="pavallion":
rate = 3500
elif s_type=="upper pavallion":
rate = 4500
elif s_type=="commentary box":
rate = 6000
elif s_type=="VIP":
rate = 8000
else:
print("Invalid Seat Types")
amt = nop * rate
if b_type=="online":
dis_per = "10%"
dis = amt * 0.1
dis_per = "8%"
dis = amt * 0.08
elif b_type=="window":
dis_per = "0%"
dis = 0
net_amt = amt - dis
print("-"*120)
print("-"*120)