0% found this document useful (0 votes)
10 views3 pages

Python Programming Lab Overview

The document outlines a Python Programming Lab course for II Year / I Semester students, focusing on basic programming constructs and Object-Oriented Programming. It includes a series of experiments and case studies designed to enhance practical skills in Python, covering topics such as data structures, functions, and modules. The course aims to equip students with the ability to solve programming problems and analyze data structures effectively.

Uploaded by

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

Python Programming Lab Overview

The document outlines a Python Programming Lab course for II Year / I Semester students, focusing on basic programming constructs and Object-Oriented Programming. It includes a series of experiments and case studies designed to enhance practical skills in Python, covering topics such as data structures, functions, and modules. The course aims to equip students with the ability to solve programming problems and analyze data structures effectively.

Uploaded by

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

PYTHON PROGRAMMING LAB

Subject Code: UGIT3P0520 L T P C


II Year / I 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 RandomCharactermodule. (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 ax2+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:


POs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1 - - - - - - - - - - - -
CO2 - 3 - - - - - - - - - -
CO3 - - 3 - - - - - - - - -
CO4 - - - 3 - - - - - - - -

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.

Common questions

Powered by AI

Case sensitivity is crucial in implementing duplicate removal because characters like 'A' and 'a' should be treated as distinct entities. Neglecting case differences could lead to incorrect results where unique characters are eliminated. Maintaining case sensitivity ensures that the function accurately processes the string, preserving the intended uniqueness of each character as per their actual occurrence .

Classes and objects are utilized to model quadratic equations effectively. A class, "QuadraticEquation," encapsulates data fields for the coefficients and methods to calculate the discriminant and roots. Objects instantiated from this class allow for storing and manipulating individual equation instances. This object-oriented approach simplifies code management and enhances scalability, enabling efficient computation of results as students input different coefficients .

The method getDiscriminant() computes the discriminant of a quadratic equation, a crucial determinant of the nature of the equation's roots. If the discriminant is positive, it indicates two distinct real roots; zero implies one real root (a repeated root), and a negative discriminant suggests no real roots (complex roots). This calculation directly influences the feasibility and method of obtaining the equation's solutions, guiding further computational processes .

Lists can be used to track letter frequency by creating an array to count occurrences of each letter, indexed by position corresponding to the alphabet. This method involves generating random letters, storing them in a list, and iterating through the list to update a frequency counter list. This allows for efficient aggregation and retrieval of letter counts, demonstrating effective data structuring and processing .

The pedagogical approach of using case studies engages students with practical, scenario-based problems, which promotes deeper understanding and application of concepts. This method targets cognitive skills such as problem-solving, critical analysis, and synthesis, as students are required to integrate various programming constructs and techniques to implement solutions. According to the course outcomes, this approach facilitates comprehension of program structures, application of primitives, and the ability to analyze data structures, aligning with Bloom's higher-order thinking skills .

The document suggests handling exceptions in Python by creating user-defined exceptions. This involves writing a program to define custom exceptions that suit specific application needs and managing them effectively within the program . A user-defined exception is an exception created by the programmer for more meaningful error handling tailored to the application's logic. Implementing these allows for robust error management, reducing the risk of unhandled errors disrupting execution .

Understanding Python programming involves familiarity with basic programming constructs such as data types, variables, loops, and conditionals, as well as advanced features like object-oriented programming. This includes creating classes and objects and handling exceptions . Additionally, competencies in manipulating data structures like lists, tuples, dictionaries, and employing modules are fundamental. Implementing these elements is crucial for developing programs and performing complex tasks .

Numpy arrays are powerful structures used in Python for efficient numerical computations. The document includes an experiment demonstrating the use of Numpy arrays, signifying their role in handling large datasets and performing mathematical operations more efficiently than using native Python lists. Numpy arrays offer a range of functions for element-wise operations, transformations, and statistical analyses, making them valuable in scientific computing and data manipulation .

Creating a Python module for operations on prime numbers involves encapsulating related functions within a file, allowing reuse across different programs. This modular approach promotes code organization, readability, and reusability. The document describes functions such as checking if a number is prime, palindromic primes, and twin primes, among others. Such a module can facilitate complex tasks like generating prime sequences or testing number properties, essential for cryptography and mathematical modeling .

A perfect number is one where the sum of its proper divisors equals the number itself. A deficient number has a sum of divisors less than the number, while an abundant number has a sum greater than the number. To find these in a Python program, one would write functions to calculate the sum of divisors and compare this sum to the number itself. Using loops and conditionals, the program can categorize numbers as perfect, deficient, or abundant and output the results .

You might also like