Python Programs for Practice with Solutions


Task -I

1. Ramesh's basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.

View Solution

2. The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.

View Solution

3. If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.

View Solution

4. Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees.

View Solution

5. The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.

View Solution

6. Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

View Solution

7. If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. ( Hint: Use the modulus operator '%')

View Solution

8. If a five-digit number is input through the keyboard, write a program to reverse the number.

View Solution

9. If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number.

View Solution

10. In a town, the percentage of men is 52. The percentage of total literacy is 48. If total percentage of literate men is 35 of the total population, write a program to find the total number of illiterate men and women if the population of the town is 80,000.

View Solution

11. A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer.

View Solution

12. If the total selling price of 15 items and the total profit earned on them is input through the keyboard, write a program to find the cost price of one item.

View Solution

13. If a five-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example, if the number that is input is 12391 then the output should be displayed as 23402.

View Solution


Task -II

1. While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than 10. If quantity and price per item are input through the keyboard, write a program to calculate the total expenses.

View Solution

2. The current year and the year in which the employee joined the organization are entered through the keyboard. If the number of years for which the employee has served the organization is greater than 3 then a bonus of Rs. 2500/- is given to the employee. If the years of service are not greater than 3, then the program should do nothing.

View Solution

3. If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of basic salary. If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic salary. If the employee's salary is input through the keyboard write a program to find his gross salary

View Solution

4. The marks obtained by a student in 5 different subjects are input through the keyboard. The student gets a division as per the following rules: Write a program to calculate the division obtained by the student.

  1. Percentage above or equal to 60 - First division
  2. Percentage between 50 and 59 - Second division
  3. Percentage between 40 and 49 - Third division
  4. Percentage less than 40 – Fail
View Solution

5. A company insures its drivers in the following cases:

  1. If the driver is married.
  2. If the driver is unmarried, male & above 30 years of age.
  3. If the driver is unmarried, female & above 25 years of age.

View Solution

6. Write a program to calculate the salary as per the following table:

Gender Year of Service Qualifications Salary
Male >= 10 Post - Graduate 15000
>= 10 Graduate 10000
< 10 Post - Graduate 10000
< 10 Graduate 7000
Female >= 10 Post - Graduate 12000
>= 10 Graduate 9000
< 10 Post - Graduate 10000
< 10 Graduate 6000

View Solution

7. If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.

View Solution

8. Any integer is input through the keyboard. Write a program to find out whether it is an odd number or even number. (Hint: Use the % (modulus) operator)

View Solution

9. A five-digit number is entered through the keyboard. Write a program to obtain the reversed number and to determine whether the original and reversed numbers are equal or not.

View Solution

10. If the ages of Ram, Shyam and Ajay are input through the keyboard, write a program to determine the youngest of the three.

View Solution

11. Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered through the keyboard. A triangle is valid if the sum of all the three angles is equal to 180 degrees.

View Solution

12. Find the absolute value of a number entered through the keyboard.

View Solution

13. Given the length and breadth of a rectangle, write a program to find whether the area of the rectangle is greater than its perimeter. For example, the area of the rectangle with length = 5 and breadth = 4 is greater than its perimeter

View Solution

14. Any year is entered through the keyboard, write a program to determine whether the year is leap or not. Use the logical operators && and ||.

View Solution

15. A certain grade of steel is graded according to the following conditions:

  1. Hardness must be greater than 50
  2. Carbon content must be less than 0.7
  3. Tensile strength must be greater than 5600

The grades are as follows:

  1. Grade is 10 if all three conditions are met
  2. Grade is 9 if conditions (i) and (ii) are met
  3. Grade is 8 if conditions (ii) and (iii) are met
  4. Grade is 7 if conditions (i) and (iii) are met
  5. Grade is 6 if only one condition is met
  6. Grade is 5 if none of the conditions are met

Write a program, which will require the user to give values of hardness, carbon content and tensile strength of the steel under consideration and output the grade of the steel.

View Solution

16. A library charges a fine for every book returned late. For first 5 days the fine is 50 paise, for 6-10 days fine is one rupee and above 10 days fine is 5 rupees. If you return the book after 30 days your membership will be cancelled. Write a program to accept the number of days the member is late to return the book and display the fine or the appropriate message.

View Solution

17. In a company, worker efficiency is determined on the basis of the time required for a worker to complete a particular job. If the time taken by the worker is between 2 – 3 hours, then the worker is said to be highly efficient. If the time required by the worker is between 3 – 4 hours, then the worker is ordered to improve speed. If the time taken is between 4 – 5 hours, the worker is given training to improve his speed, and if the time taken by the worker is more than 5 hours, then the worker has to leave the company. If the time taken by the worker is input through the keyboard, find the efficiency of the worker.

View Solution


Task -III

1. Write a program to find the factor of the given number.

View Solution

2. Write a program to find whether the given number is prime or not.

View Solution

3. Write a program to find the given number is Armstrong number or not.

View Solution

4. Write a program to print the Armstrong numbers between 100 to 999.

View Solution

5. Write a program to count and print the number of odd and even numbers.

View Solution

6. Write a program to find the reverse of n digit number using While loop

View Solution

7. Write a program to find the binary number from given decimal number.

View Solution

8. Write a program to find the decimal number from given Binary number.

View Solution

9. Write a program to find the factorial of the given number.

View Solution

10. Write a program to find the Fibonacci Series of the given number.

View Solution

11. Write a program to find the given number is perfect number

View Solution

12. Write a program to print the perfect number between 1-1000

View Solution

13. Write a program to find the given number is strong number

View Solution

14. Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another.

View Solution



List of Programs


Sample Programs


Python Database Connection


Python Flask


Python Tkinder Tutorial