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

[1] 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()
```

[2] 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()
```

[3] 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()
```

[4] 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()
```

[5] 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()
```

[6] 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()
```

[7] 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()
```

[8] 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()
```

[9] Find minimum number out of given three numbers.

**Do it yourself.**

Watch this video lesson explains the programms.

[10] 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()
```

[11] 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()
```

[12] 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()
```

[13] 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()
```

[14] A function f is defined as follows :

f(x) = ax^{3} â€“ bx^{2} + cx â€“d, if x > k

= 0, if x = k

= -ax^{3} + bx^{2} – 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()
```

[15] 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 addition\n")
print("- for addition\n")
print("* for addition\n")
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")
print("The answer is:",ans)
sol15()
```

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

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

Units Consumed | Charges |

0-100 | 0.50 per unit |

101-200 | Rs. 50 plus Rs. 1 per unit over 100 units |

201-300 | Rs. 150 plus 1.50 per unit over 200 units |

> 300 | Rs. 300 plus Rs.2 per unit over 300 units |

- Ask user to enter the Past meter reading and current meter reading.
- Find the units consumed.
- 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()
```

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

Amount | Shorts | Pants | Shits/T-Shirts |

0-100 | – | 3% | 5% |

101-200 | 5% | 8% | 10% |

201-300 | 10% | 12% | 15% |

Above 300 | 18% | 20% | 22% |

- 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.
- 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()
```

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

Category | Units | Rate |

Commercial | Minimum up to 5000 units | Rs. 1500 |

Next 5000 units | Rs. 0.25 per unit | |

Next 10000 units | Rs. 0.23 per unit | |

Above this | Rs. 0.20 per unit | |

Institutional | Minimum up to 5000 units | Rs. 1800 |

Next 5000 units | Rs. 0.30 per unit | |

Next 10000 units | Rs. 0.28 per unit | |

Above this | Rs. 0.25 per unit | |

Domestic | Minimum up to 100 Units | Rs. 75 |

Next 100 Units | Rs. 1.25 per unit | |

Next 200 Units | Rs. 2.00 per unit | |

Above this | Rs. 2.50 per unit |

- Ask user to enter customer category, Units.
- Compute the bill as per given criteria.
- 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()
```

[19] A transport company charges the fare according to following table:

Distance | Charges |

1-50 | 8 Rs./Km |

51-100 | 10 Rs./Km |

> 100 | 12 Rs/Km |

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()
```

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

- Ordinary – 2500
- Pavillion – 3500
- Upper Pavillion – 4500
- Commentary Box – 6000
- 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.

- Ask user to enter the booking type like online, advance or window booking.
- Ask user to select the types of seats.
- 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
elif b_type=="advanced":
dis_per = "8%"
dis = amt * 0.08
elif b_type=="window":
dis_per = "0%"
dis = 0
net_amt = amt - dis
print("-"*120)
print("\t\t\tSardar Patel Cricket Stadium - Motera, Ahmedabad")
print("-"*120)
print("Your Seats:",s_type,"\t Booking type:",b_type)
print("No of seats:",nop,"\t Amount (before discount):", amt)
print("-"*120)
print("Discount in (%):",dis_per,"\t Discount amount:",dis)
print("Bill amount is", net_amt)
sol20()
```

Read notes for this concept from here.

Dear Students do these programs for your practical files, this program list with your friends. Feel free to comment your views on this article and ask your doubts as well. Thank you for visiting my blog.

[su_button url=”https://drive.google.com/drive/u/1/folders/1YNhUR-gtAFsi-FwYAWDuLrwk9d2x6smG” target=”blank” style=”3d” background=”#040e73″ color=”#f7f1f0″ size=”7″ icon=”icon: file-o” text_shadow=”5px 5px 5px #000000″]Download[/su_button]