0% found this document useful (0 votes)
1 views4 pages

CS-255 - Python Programming Lab

The document outlines the curriculum for a Python Programming Lab course, detailing course objectives, programming exercises, and expected outcomes. It includes various programs focusing on control structures, data types, functions, classes, inheritance, polymorphism, file handling, exception handling, and multithreading. Additionally, it lists reference books and course outcomes related to data structures, problem-solving, exception handling, and database connectivity.

Uploaded by

rajsoni.msil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views4 pages

CS-255 - Python Programming Lab

The document outlines the curriculum for a Python Programming Lab course, detailing course objectives, programming exercises, and expected outcomes. It includes various programs focusing on control structures, data types, functions, classes, inheritance, polymorphism, file handling, exception handling, and multithreading. Additionally, it lists reference books and course outcomes related to data structures, problem-solving, exception handling, and database connectivity.

Uploaded by

rajsoni.msil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Course Code Course Name L T P Credits

CS-255 Python Programming Lab 0 0 2 1

Course Objective:
1. To build programming logic and thereby developing skills in problem solving using Python programming
language.
2. To be able to do testing and debugging of code written in Python Emphasize the concepts and constructs
rather than on language features.

Program 1: Programs using if else structure


a) Find the Largest Among Three Numbers
b) Python Program to Check Leap Year
c) Python Program to take in the marks of 5 Subjects and Display the Grade
d) Python Program to check if a Date is Valid and Print next date

Program 2: Programs using for and while loop


a) Python Program to check whether given number is Prime Number or not
b) Python Program to find LCM of two numbers
c) Write a Python Program to compute the GCD of two numbers
d) Python Program to find the Sum of Digits in a number
e) Python Program to convert binary number to decimal numbers
f) Python Program to Display Fibonacci sequence using Recursion

Program 3: Program using List and String Data Sequence


a) Write a Python Program to input a list of Integers,
1. Display the numbers of elements in the list
2. Display minimum and maximum element in the list
3. Display sum of square of all the elements in the list
4. Add a new element a tend and display the list
5. Add a new element at given index and display list
6. Display the occurrence of given element in the list
7. Remove the given element in the list
8. Add a new element from a new list from the given list
9. Sort the given list & reverse the given list
10. Also perform slicing, concatenation and multiplication operation.

b) A fruit seller sells different types of fruits. Type of fruits and corresponding rates are stored in two different lists.
Customers can order any type of fruit (one or more type) in any quantity. If the total bill of the customer is greater than
500, customer is given 10% discount. If any of the fruits required by the customer is not available in the store, then
consider the bill amount to be-1.
Write a Python Program to calculate and display the bill amount

c) Write a Python Program to display all the permutation of the given string (don’t use python permutation function)

d) Accept two strings ‘string 1’ and ‘string 2’ as input from the user. Generate a resultant string-1 such that it is a
concatenated string of all upper-case alphabets from the both strings in the order they appear. Generate a resultant string-
2 that contains characters which are in both string1 and 2. Print the actual resultant string1 and resultant string2

Program 4: Program using concepts of sets, tuple and dictionary


a) Write a Python Program that takes a string as input and store the character and occurrence of each character in a
dictionary. Create two lists from the dictionary, first having each character in a sorted order of their frequency and second
having corresponding frequency.
b) A furniture seller sells different types of furniture. Types of Furniture and Rates are stored in a dictionary. Customer can
order any type of furniture (one or more type) in any quantity. If total bill of customer is greater than10,000 customer is
given 5% discount. 8% GST is charged on the total bill. If any of the furniture required by the customer is not available in
the store, then consider the bill amount to be -1. Write a python Program to calculate and display the bill amount.

c) Consider a scenario from Lingaya’s Vidyapeeth. Given below are two sets representing the names of the students
enrolled for the particular course: java course= {“Anmol”,” Rahil”, ”Priyanka”, ”Pratik’} python_ course = {“Rahul”, ”Ram”,
“Nizam”,”Vishal”} Write a Python Program to list the number of students enrolled for:

1) Python Couse
2) Java Course only
3) Python Course only
4) Both Java and Python Courses
5) Either Java or Python Courses but not both
6) Either Java or Python

d) Students name and their corresponding marks are stored in dictionary. Write a Python Program. Write a Python
Program to perform following:
1) Display name and marks of each student.
2) Display the name of the two top scorers.
3) Display the class average for this course.
4) Check if the mark for given student is stored in dictionary or not, if not add the name and marks in the dictionary else
display his/her marks.
5) Delete the name and marks of a given student in the dictionary.
6) Add name and marks from another dictionary and display combine dictionary.

Program 5: Using Function in Python


a) Write a Python function using the concept of Keyword & Default arguments and write a program to use them.
b) Write a Python function to use the concept of variable length argument & global variable. Write a program to use
these functions.
c) Write a recursive function to solve the Tower of Hanoi Problem

Program 6: Program using concept to f Class, Object, Class variable, Class method, Static method
a) Create a class account with name, account number and balance as attribute and no_of_accounts as class variable.
Account numbers should be generated automatically (starting from 1) using the class variable no_of_accounts. Add the
methods for displaying the account information, depositing given amount, withdrawing given amount and initializer
method to initialize the object. Create objects of Account class and call different method to test the class.
b) Create a class Employee with name, empid, salary as attribute and no_of_employee and annual_incr (%annual
increment) as class variable, empid should be generated automatically (starting from 1) using the class variable,
no_of_employee. Add the instance methods for displaying the employee information, annually increasing the salary
with help of class variable annual_incr, class method to change the value of annual_incr and initializer method to test
the class program (using class method).
c) Write a Program to showing the use of built in class attributes (_doc_,dict_,_name_,_module_,_bases_) and special
methods(_del_(),_str_()) and built in function is instance()

Program 7: Program using the concept of Inheritance


a) Create a class Polygon to represent a polygon having number of sides and a list having magnitude of each side as
attribute. Add the input Sides () to input sides and display sides () to display sides as methods. Derive a class Triangle
from Polygon and add an additional method display Area () to display area. Create object of Triangle and call different
methods to test the class.
b) Create a class person having name, age, as attributes, _init_ () method to initialize the object and display () to display
person information. Derive a class Student from person having roll number, University name, branch as additional
attributes and _init_ (), display () to display student information and change Branch () method. Create object of
Student type and call different methods to test the class.
c) Write a program to show the concept of multiple inheritance in python.

Program 8: Program using the concept to f Polymorphism, operator over loading


a) In a retail outlet there are two modes of bill payment.
1. Cash: Calculation includes VAT (10%) Total Amount=Purchase amount + VAT
2. Credit Card: Calculation includes Processing Charge and VAT Total Amount= Purchase amount +VAT (10%) +Processing
Charge (2%).
3. The act of bill payment is same, but the formula used for calculation of total amount differs as per the mode of
payment. Can the Payment maker simply call a method and that method dynamically selects the formula for the total
amount? Demonstrate this Polymorphic behavior with code.
b) Write a Program to create a class to represent length in feet and inch. Overload the “+” operator to add the two object
of length type.
c) Write a Program to overload comparison operator in python.

Program 9: Program on file handling in Python


a) Write a Python Program to write a few lines on file, read it back and create a dictionary having each word in file as keys
in dictionary and occurrence of these word as values and print the dictionary.
b) A file student .txt store student information. Information about each student is written on separate line in the form:
roll number student-name (student-name may consist of any number of words). Write a Python Program that takes
student roll number as input and prints the student’s name. If roll number is not present in the file, it displays: “roll no
not present in the file”.
c) Write a Python Program to read a file that contains email ids on the separate lines in the form:
personname@[Link]. Create a new file that contain only company names, read the new file to print the
company name.

Program 10: Program on Exception Handling


a) Write a function divide (arg1, arg2) to divide arg1 by arg2. Use the exception handling mechanism to handle all type of
possible exceptions that may occur. Take the value of arg1 and arg2 (of any type) from user as input and call the
function divide to print the result of division or suitable message if any type of exception occurs (use also else and
finally block).
b) Write a program to open a file in read only mode data from file and then try to write data on file. Use the exception
handling mechanism to handle all types of possible exception.
c) Write a python program that takes the email id, mobile number and age as inputs from user. Validate each and use
raise user defined exceptions accordingly.
Email id: there must be only one@ and at least one “.”Mobile number must be 10 digits
Age must be a positive number less than 101.

Program 11: Program on multi-threading


a) Write two functions: print even (n) and print odd (n) to print even numbers and print odd numbers respectively up to
integer n. Create two thread objects by passing these functions in thread class constructor to execute these functions
in two different threads. Use sleep () methods to see how these functions are executed concurrently (*use start ()
method to start and join () method to wait for thread to terminate)
b) Write a Python Program to use the concept of multithreading by Overriding run () method in a sub class of threading.
Thread
c) Write a Python Program using the concept of thread synchronization.

Reference Books:
1. T. Budd Exploring Python, TMH,1st Ed.2011
2. Allen Downey, Jeffrey Elkner, Chris Meyers, how to think like a computer scientist: Learning with Python, freely
available online.2012
3. John V Guttag “Introduction to Computation and Programing Using Python”, Prentice Hall of India
Course Outcomes:
CO1: Define and demonstrate the use of built-in data structures “list “and “dictionary”.
CO2: Design and implement a program to solve a real-world problem.
CO3: Solve exception handling problem and files.
CO4: Make data base connectivity in python programming language.

You might also like