PYTHON PRACTICE SHEET (if else, ladder/ nested if)
1. Check the output of the following question:
str='s'
if(str.islower()):
print(str.upper())
elif(str.isupper()):
print(str.lower())
2. Write a program to input a digit (0 – 9) and print the number names.
3. Check the output of the following question:
tc=input("enter the total cost of items ")
dis=0
if(tc<=2000):
dis=tc*5/100
elif(tc>=2001 and tc<=5000):
dis=tc*25/100
elif(tc>=5001 and tc<=15000):
dis=tc*35/100
elif(tc>=15001):
dis=tc*50/100
print("Cost after discount is",tc-dis)
4. Check the output of the following question:
marks=input("Enter your total marks out of 500 ")
if(marks>=400):
print"SCIENCE Stream"
elif(marks>=250 and marks<=399):
print"COMMERCE Stream"
elif(marks>=165 and marks<=249):
print"HUMANIITES Stream"
elif(marks>=0 and marks<=164):
print"No Stream"
5. Write a program to input two integers a, b. Interchange values stored in a, b. Print values of a, b before and
after interchange using suitable messages.
6. Write a program to input a character. Check and print whether it is a capital alphabet or small alphabet or a
digit. Print the character along with suitable message.
7. Write a program to input a character and convert into its opposite case. Print the original character and new
character.
8. Write a program to input a character. Print next five characters including the given character. Input the
character not beyond ‘v’. The character may be in upper case or in lower case.
9. Write a program to input a character check if it is an alphabet then convert into upper case form if it is
lowercase. Print the next five characters in circular alphabet list including the modified character.
10. Write a program to input two integers and a character. The character contains any one of the arithmetic
operator (+, -, *, / or %). Your program should check the operator entered and perform the corresponding
operation.
11. Write a program to input basic and to find the gross pay of an employee for the following allowances and
deduction.
Dearness allowance = 25 % of Basic.
House Rent Allowance = 15% of Basic.
Provident Fund = 8.33% of Basic.
Net Pay = Basic + Dearness Allowance + House Rent Allowance.
Gross Pay = Net Pay – Provident Fund.
12. Write a program to find the roots i.e. x1, x2 by inputting the value of a, b, c from the following relation.
−𝑏±√𝑏 2−4𝑎𝑐
𝑥=
2𝑎
13. Write a program to calculate and print roots of a quadratic equation ax2 + bx + c = 0 (a!=0)with appropriate
messages the root are given by:
−𝑏 ± √𝑏2 − 4𝑎𝑐
𝑥1 𝑎𝑛𝑑 𝑥2 =
2𝑎
If b2 – 4ac > 0 then roots are real and unequal.
If b2 – 4ac = 0 then roots are real and equal.
If b2 – 4ac < 0 then roots are imaginary.
14. Write a program to input a character and print whether it is a digit or a white space.
15. Write a program to input hours and minutes in two different variables. Convert hours to minutes and minutes
to hours.
16. Write a program to convert a given temperature from Fahrenheit to Celsius and vice versa. For an incorrect
choice, an appropriate message should be displayed. C= 5/9 x (F-32) , F = 1.8 x (C + 32)
17. A cloth showroom has announced the following festival discounts on the purchase of items based on the total
cost of the items purchased.
Total Cost Discount (in Percentage)
Less then Rs. 2000 5%
Rs. 2001 to Rs. 5000 25%
Rs. 5001 to Rs. 10000 35%
Above Rs. 10000 50%
Write a program to input the total cost and to compute and display the amount to be paid by the customer.
18. The telephone department wishes to compute monthly telephone bills for its customers using the following
rules on the basis of call made:
Number of calls Rate
First 80 calls Rs. 250/-
Next 80 Calls 60 paisa per call
Next 160 Calls 50 paisa per call
Any call above 280 Calls 40 paisa per call
Write a program to input number of calls and compute total bill amount.
19. An institute has decided to admit new candidates in different streams on the following criteria:
Total marks obtained Stream offered
300 and above SCIENCE
200 and above but less than 300 COMMERCE
Below 200 but not below 75 HUMANITIES
Otherwise Admission is not granted.
Write a program to input total marks obtained in an examination and print the stream allotted.
20. Write a program to compute salesman commission on the following basis:
Sales (Rs.) Commission
1 – 100000 15%
100001 – 200000 25%
Above 200000 45%
21. Write a program with three integer values as a three sides of a triangle and decide whether it is a scalene,
isosceles or equilateral triangle.
22. An employee is entitled to pay an income tax based on his gross annual income as per the given rule:
Gross annual income (Rs.) Annual tax deduction
Less than or equal to 100000 NIL
100001 to 150000 10% of the income exceeding 100000
150001 to 200000 5000 + 20% of the income exceeding 150000
Above 200000 15000 + 30% of the income exceeding 200000
Write a program to input gross annual income and print the payable income tax by the employee.
23. A Library charges a fine for books returned late. Following are the fines:
First Five Days: 40 paise per day
Six to Ten Days: 65 paise per day
Above Ten days: 100 paise per day
Write a program which takes as input the number of days late and prints the fine.
24. Write a program to enter a character and check whether it is a vowel or consonant. Your program should print
the given character along with the suitable message.
25. Write a program to input two lengths in feet and inches. Add the length and print the sum of lengths.
Example: Let Length1 = 8 feet 17 inch
Let Length2 = 7 feet 10 inch
Sum of Length1 and Length2 is = 17 feet 03 inch ( where 12 inch = 1 feet)
26. Write a program to input two timings in degrees and minutes. Add the timings and print the sum of timings.
Example: Let time1 = 20 degree 80 minutes
Let time2 = 10 degree 70 minutes
Sum of time1 and time2 is = 32 degree 30 minutes (where 60 minutes = 1 degree)
27. Write a program to input 3 integers and find the greatest from them.
28. Write a program to input 3 integers and find the lowest from them.
29. Write a program to input a digit (0 – 9) and print the number names.
30. Write a program to input week number and print day of week.
31. Write a program to input month number and print name of the month.
32. Write a program to input number and print its absolute value of a number. (Without using function)
33. Write a program to input a number (between 1 – 12) print the name of month using the number.
34. Write a program to input a number (between 1 – 7) print the name of week using the number.
35. Write a program to print the various designations on the basis of the first letter given as input. The
designations are limited in the process as given: Manager, Producer, Charted Accountant, Engineer, Minister,
Officer and Teacher. Input a character (in capital or small) and print the corresponding designation. Input: M
Output: Manager
36. Write a program to input a two digit number (your program should display a message if the number is not
having two digits). Split both the digits of that number and print the corresponding number name for each
digit. Input: 46 Output: Four Six / SIX FOUR