Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

Programs on Python (AutoRecovered)

Uploaded by

shivankpandey48
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Programs on Python (AutoRecovered)

Uploaded by

shivankpandey48
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Python Programs Topic Wise

Topic – 1 (Introduction to Python)


1. Write a python program to print a message on screen.
2. Write a python program to take two numbers as input now find summation,
subtraction, multiplication and division of two numbers.
3. Write a python program to find area and perimeter of circle.
area=3.14*r*rgf
perimeter=2*3.14*r
4. Write a python program to find volume and surface area of cuboid.
v=l*b*h
sa=2*(l*b+b*h+h*l)
5. Write a python program to find simple interest.
si=(p*n*r)/100
6. Write a python program to find square root of a number.
root=math.sqrt(n)
7. Write a python program to take number of days as input now display years, weeks
and days. E.g. If user input 375 days then output will be 1 years, 1 weeks and 3 days.
In this program ignore leap year.
8. Write a python program to compute area of perimeter of rectangle.
area=l*b
perimeter=2*(l+b)

Topic – 2 (Flow control in Python)


1. Write a python program to check given number is even or odd.
2. Write a python program to find greatest number in two numbers.
3. Write a python program to find roots of quadratic equation ax2+bx+c=0.
root1=(-b+math.sqrt(b*b-4*a*c))/(2*a)
root2=(-b-math.sqrt(b*b-4*a*c))/(2*a)
4. Write a python program to take coordinates of a point as input and determine its
quadrant.
5. Write a python program to compute gross salary based on following parameters:-

Basic Salary HRA DA


1-4000 10% 50%
4001-8000 15% 60%
8001-12000 20% 70%
More than 12000 25% 80%

gs=bs+hra+da
6. Write a python program to calculate electricity bill based on following parameters:-

Units Bill/unit
1-150 2.40
For next 151-300 3.00
For next more than 300 3.20

7. Write a python program to print table of given number in given format:-


2*1=2
2*2=4
2*3=6
.
.
2*10=20

8. Write a python program to find factorial of given number.


9. Write a python program to find sum of digits of given number.
10. Write a python program to reverse the digits of given number.
11. Write a python program to convert binary number to its decimal equivalent.
12. Write a python program to check given number is prime or not.
13. Write a python program to print series of prime numbers in given range. Range
must be created by taking input from user.
14. Write a python program to print Fibonacci series up to n terms, where value of n is
entered by user.
15. Write a python program to check given number is Armstrong or not.
Topic – 3 (Collections in Python)
1. Write a python program to create a list of ten numbers by taking input from user.
Now find sum and average of numbers.
2. Write a python program to create a list of ten numbers by taking input from user.
Now check a number is presented in list or not.
3. Write a python program to create a list of ten numbers by taking input from user
named AR. Now copy even numbers in list EAR and odd numbers in list OAR. Now
display elements of EAR and OAR.
4. Write a python program to create a list of five students by taking input from user.
Now display name of students in ascending and descending order.
5. Write a python program to create a tuple of five numbers. Now apply len(), max(),
min() and sum() functions on tuple.
6. Write a python program to find number of occurrences of each vowel present in the
given string?
7. Write a python program to create a set of ten numbers by taking input from user.
Now traverse set elements.
8. Write a python program to create a dictionary and traverse elements of dictionary
using for loop.
9. Write a python program to create a dictionary by taking input from user. Now
traverse elements of dictionary.
10. Write a python program to convert a list into tuple.
Lecture – 4 (Functions and modules)

1. Write a python program to create two functions area() and peri() to find area and
perimeter of rectangle.
2. Write a python program to create a function calc(), write code to find summation,
subtraction, multiplication and division and return result in form of list. Now test
calc() function.
3. Write a python program to create a function search(), in search function pass two
parameters first, a list of ten numbers and second, a number to search. If number is
present in list return index of list otherwise return false.
4. Write a python program to create a function named substr(), in substr() function
pass a string and substring. If substring is presented in string then return true or
return false.
5. Write a python program to create a function named rev(), in rev() function pass a
string and this function return reverse string.
6. Write a python program to find factorial of given number using ‘Recursion’.
7. Write a python program to generate Fibonacci series up to n terms using ‘Recursion’.
8. Write a python program to create a module named mycalc. In mycalc module create
four functions add(), sub(), mult() and div() to find summation, subtraction,
multiplication and division respectively. Now import mycalc module and test these
functions.
9. Write a python program to create a module named tempconv. In tempconv module
create two function ctof() and ftoc(). ctof() function converts temperature from
centigrade to Fahrenheit and ftoc() function converts temperature from Fahrenheit
to centigrade. Now import tempconv module and test ctof() and ftoc() functions.
10. Write a python program to create a function random(). This function return random
number from 1-10.

Topic – 5 (Object Oriented Programming)

1. Write a python program to create a class with name ‘MyClass’. In MyClass create a
function sayHello(). In sayHello() function pass name of user, and display user name
with Hello, message. Test class ‘MyClass’.
2. Write a python program to create a class with name ‘Employee’. In Employee class
take three instance variables empid, empname and salary. Create two methods in
Employee class first setEmployee() and second display(). setEmployee() method
initialize instance variables empid, empname, salary and display() method display
value of empid, empname and salary. Now test Employee class.
3. Write a python program to create a class with name ‘Rectangle’. In ‘Rectangle’ class
take two instance variables length and breadth. Now create a parameterized
constructor to initialize variables and create a method area() which return area of
rectangle. Test the class ‘Rectangle’.
4. Write a python program to create a class with name ‘Student’. In Student class take
three instance variables rollno, name and fee. Now create a parameterized
constructor to initialize variables and create a method display() which display values
of instance variables. Test the class ‘Student’.
5. Write a python program to create a class with name ‘Bank’. In Bank class take three
instance variables acno, name and balance. Create a parameterized constructor to
initialize instance variables. Now create following methods in Bank class:-
i. deposit() – This method is used to deposit() money in account.
ii. withdraw() – This method is used to withdraw money from account after
checking balance.
iii. enquiry():- This method provide balance enquiry.
Topic – 6 (Inheritance in Python)

1. Write a python program to create a class named Base. In Base class create a method
showBase(), this method display a message ‘This message from base class’. By
inheriting Base class now create a class named Derived. In Derived class create a
method showDerived(), this method display a message ‘This message from derived
class’. Now test Base and Derived class.
2. Write a python program to create a class named Shape. In Shape class create a
method named setValue(), this method initialize side of shape. By inheriting Shape
class create a new class Square. In Square class create a method area(), this method
return area of square. Now by inheriting Shape class create a new class Cube. In
Cube class create a method volume(), this method return volume of cube. Now Test
Square and Cube classes.
3. Write a python program to create a class Employee. In Employee class take two
instance variables empid and empname. In Employee class create two methods
setEmployee() and getEmployee(). setEmployee() method is used to initialize
instance variables empid and empname whereas getEmployee() method is used to
display values of empid and empname. By inheriting Employee class create a new
class Payroll. In Payroll class create three instance variables bs, hra and da. In Payroll
class create two methods setPayroll() and getPayroll(). setPayroll() method is used to
initialize variables bs, hra and da whereas getPayroll() method is used to display
values of bs, hra and da. Now by inheriting Payroll class create a new class Payslip. In
Payslip class create a method named netSalary() which displays net salary with
addition of basic salary, hra and da. Now test Payslip class. This is an example of
multilevel inheritance.
4. In program (3) create a class Loan before the code of Payslip class. In Loan class
create a method setLoan() which is used to initialize amt variable. Now inherit Loan
class in Payslip class and in netSalary() method also print salary on hand as
(bs+hra+da-amt). This is an example of hybrid inheritance.
5. Write a python program to demonstrate super keyword.

Topic – 7 (Polymorphism and Exception Handling)


1. Write a program in python to create a class with name Figure. In Figure class create a
single method named area(), by using area() method find area of square and
rectangle as an example of method overloading.
2. Write a program in python to create a class with name Bank. In Bank class create a
method interest() which return 0 value. Now override interest method in class Sbi
and Pnb.
3. Write a program in python to find division of two numbers. Also handle ValueError
and ZeroDivisionError in same program.
4. Write a program in python to open a file for read operation. Also handle
FileNotFoundError.
5. Write a program in python to take a decimal number as input and convert it into
binary, octal and hexa-decimal equivalent.
Topic – 8 (String handling in python)
1. Write a program in python to take a string as input. Now convert string into upper
case, lower case and title format.
2. Write a program in python to take a string as input. Now check given string is
palindrome or not.
3. Write a program in python to search a substring in given string.
4. Write a program in python to take a sentence as input. Now count words in given
sentence.
5. Write a program in python to take a sentence as input. Now count occurrence of
‘The’ word in given sentence.
6. Write a program in python to take full name as input. Now display short name of
user.
7. Write a program in python to take a sentence as input. Now in given sentence
replace a word with another word.
8. Write a program in python to check given string is numeric or not.
9. Write a program in python to count digits in an alphanumeric string.
10. Write a program in python to use Boolean methods of string.

You might also like