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

Python Programming Lab

This document outlines the Python Programming Lab course for first year students. The course introduces students to basic Python programming concepts like data types, control structures, functions, classes and modules through experiments and case studies. Students will learn to implement basic programs, understand object-oriented concepts, and develop programs to solve problems. Upon completing the course, students will be able to write Python programs, use various data structures, and analyze and develop solutions for given scenarios.

Uploaded by

tejvarmavarma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
143 views4 pages

Python Programming Lab

This document outlines the Python Programming Lab course for first year students. The course introduces students to basic Python programming concepts like data types, control structures, functions, classes and modules through experiments and case studies. Students will learn to implement basic programs, understand object-oriented concepts, and develop programs to solve problems. Upon completing the course, students will be able to write Python programs, use various data structures, and analyze and develop solutions for given scenarios.

Uploaded by

tejvarmavarma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 4

PYTHON PROGRAMMING LAB

(Common to All Branches)

Subject Code: UGCS2P0320 L T P C


I Year / II Semester 0 0 3 1.5

Prerequisites: Basic understanding of Computer Programming terminologies.

Course Objectives:
 To be able to implement the basic programming constructs
 To understand the features of Object-Oriented Programming

Experiments:

1. Write a program to demonstrate different representations of numbers in Python.


2. Write a program to perform different complex Arithmetic Operations on numbers in
Python.
3. Develop programs to demonstrate decision making and looping structures in
python.
4. Write a program to demonstrate working with lists in python.
5. Write a program to demonstrate working with tuples in python.
6. Write a program to demonstrate working with dictionaries in python.
7. Write a program to create a module by adding a method and import the module in
the application.
8. Write a program to create user defined exception and handle the exception in the
application.
9. Write a program to demonstrate how to create classes and objects in the
application.
10. Demonstrate the use of Numpy arrays in python

Case Studies:

1. Case study on Loops:


A perfect number is a number for which the sum of its proper divisors is exactly
equal to the number. For example, the sum of the proper divisors of 28 would be 1
+ 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number. A number n is
called deficient if the sum of its proper divisors is less than n and it is called
abundant if this sum exceeds n. Write a program for the given large n, find the sum
of all perfect numbers, sum of all deficient numbers and sum of abundant numbers
separately. Print all perfect numbers along with its sum, deficient numbers along
with its sum and abundant numbers along with its sum.

2. Case studies on Functions:


a) Write a function “remove_duplicates” which takes a string argument and returns
a string which is the same as the argument except only the first occurrence of each
letter is present. Make your function case sensitive.
b) Write a function mult_lists(a, b) that takes two lists of numbers of the same
length, and returns the sum of the products of the corresponding elements of each.
c) Write a function called flatten_list that takes as input a list which may be nested,
and returns a non-nested list with all the elements of the input list.

3. Case study on modules:


Create a module “Prime” to include the following functions.
a) isPrime(number) : returns Boolean whether the given number is prime number
or not.
b) isPalindromePrime(number) : returns Boolean whether the given number is
prime with palindromic. Example 131 is a palindromic prime.
c) isEmirp(number) : returns Boolean whether the given number and its reversal
number are also prime numbers. Example 17 and 71 are both Emirps.
d) mersennePrime(p): returns 2p – 1 value for given integer p if it is prime number.
e) printTwinPrimes(range) : prints all twin prime numbers below given range.

Write a test program to import the Prime module and perform the following
operations using the functions of Prime module.

 Prints first 100 prime numbers.


 Prints first 100 Palindrome prime numbers.
 Prints first 100 Emirp numbers.
 Prints all Mersenne prime numbers for the p value below 32.
 Prints all twin prime numbers below 1000.

4. Case study on Lists:


Counting the occurrence of each letter.
The program counts the occurrence of each letter among 100 letters.
Procedure
 Generates 100 lowercase letters randomly and assigns them to a list of
characters, named chars. You can obtain a random letter by using the
getRandomLowerCaseLetter() function in the RandomCharacter module.
(Import RandomCharacter module into your program)
 Counts the occurrences of each letter in the list. To do so, it creates a list named
counts that has 26 int values, each of which counts the occurrences of a letter.
That is, counts[0] counts the number of times a appears in the list, counts[1]
counts the number of time b appears, and so on.
5. Case study on Classes
Design a class named QuadraticEquation for a quadratic equation ax 2+bx+c =0.
The class contains:
 The private data fields a, b, c that represents three coefficients.
 A constructor for the arguments for a, b and c
 Three get methods for a, b and c
 A method named getDiscriminant() that returns the discriminant, which is
b2-4ac.
 The methods named getRoot1() and getRoot2() for returning the two roots of
the equation using the formulas:
R1 = -b + (√b2-4ac)/2a and R2 = -b – (√b2-4ac)/2a.
 These methods are useful only if the discriminant is non negative. Let these
methods return 0 if the discriminant is negative.
 Write a test program that prompts the user to enter values for a, b, c and
displays the result based on discriminant.

Course Outcomes:
Upon completion of the course, the students will be able to:
CO 1. Understand python programming structure for solving basic programming
problems.[L2]
CO 2. Use primitive data types, selection statements, loops, function, and classes to
write programs. [L3]
CO 3. Develop programs for a given scenario. [L3]
CO 4. Analyze different data structures and choose suitable one for a given problem.
[L4]

Mapping of COs to POs:


PO PO PO PO PO PO PO PO PO PO1 PO1
POs PO12
1 2 3 4 5 6 7 8 9 0 1
CO
- - - - - - - - - - - -
1
CO
- 3 - - - - - - - - - -
2
CO
- - 3 - - - - - - - - -
3
CO - - - 3 - - - - - - - -
4

TEXT BOOKS:
1. Python Programming using problem solving approach, Reema tharaja, Oxford
University Press, 1st Edition.
2. Fundamentals of Python, Kenneth a. lambert, B.L. Juneja, Cengage Learning, 1 st
Edition.
3. Chun, J Wesley, Core Python Programming, 2nd Edition, Pearson.

REFERENCE BOOKS:
1. Python How to Program, Dietel and Dietel, 1st Edition.
2. Barry, Paul, Head First Python, 2nd Edition, O Rielly.
3. Lutz, Mark, Learning Python, 4th Edition, O Rielly.

You might also like