CSE-R-2019
R G M COLLEGE OF ENGINEERING & TECHNOLOGY, NANDYAL
AUTONOMOUS
COMPUTER SCIENCE AND ENGINEERING
II [Link]. I-Sem (CSE) P C
3 1.5
PYTHON PROGRAMMING LAB (A0594193)
(Common to all Branches)
COURSE OBJECTIVES:
To be able to introduce core programming basics and various Operators of Python
programming language.
To demonstrate about Python data structures like Lists, Tuples, Sets and
dictionaries
To understand about Functions, Modules and Regular Expressions in Python
Programming.
COURSE OUTCOMES:
Student should be able to understand the basic concepts of scripting and the
contributions of scripting language.
Ability to explore python data structures like Lists, Tuples, Sets and dictionaries.
Ability to create practical and contemporary applications using Functions, Modules
and Regular Expressions.
MAPPING OF COs & POs
T
PO PO PO PO PO PO PO PO PO PO PO PO PSO PSO PSO
CO/PO
1 2 3 4 5 6 7 8 9 10 11 12 1 2 3
CO1 3 1 2 1 1 1 1
CO2 3 3 2 1 1 1 1
CO3 3 1 2
CE 1 1 1 1
[Link] Name of the Experiment Remarks
1 a) Demonstrate about Basics of Python Programming.
M
b) Demonstrate about fundamental Data types in Python
Programming. (i.e., int, float, complex, bool and string
types)
c) Demonstrate the working of following functions in
Python.
RG
i) id( ) ii) type( ) iii) range( )
d) Write a Python program to demonstrate various base
conversion functions.
e) Write a Python program to demonstrate various type
conversion functions.
2 a) Demonstrate the following Operators in Python with
suitable examples.
i) Arithmetic Operators ii) Relational Operators
iii) Assignment Operator iv) Logical Operators
v) Bit wise Operators vi) Ternary Operator
vii) Membership Operators viii) Identity Operators
3 a) Write Python programs to demonstrate the following:
i) input( ) ii) print( )
iii) ‘sep’ attribute iv) ‘end’ attribute
v) replacement Operator ({ })
b) Demonstrate the following Conditional statements in
Python with suitable examples.
i) if statement ii) if else statement
iii) if – elif – else statement
CSE-R-2019
R G M COLLEGE OF ENGINEERING & TECHNOLOGY, NANDYAL
AUTONOMOUS
COMPUTER SCIENCE AND ENGINEERING
c) Demonstrate the following Iterative statements in Python
with suitable examples.
i) while loop ii) for loop
d) Demonstrate the following control transfer statements in
Python with suitable examples.
i) break ii) continue iii) pass
4 Write Python programs to print the following Patterns:
i)
T
ii)
CE
M
RG
iii)
iv)
CSE-R-2019
R G M COLLEGE OF ENGINEERING & TECHNOLOGY, NANDYAL
AUTONOMOUS
COMPUTER SCIENCE AND ENGINEERING
v)
vi)
T
vii)
CE
M
RG
viii)
5 a) Write a Python program to demonstrate various ways of
accessing the string.
i) By using Indexing (Both Positive and Negative)
ii) By using Slice Operator
b) Demonstrate the following functions/methods which
operates on strings in Python with suitable examples:
i) len( ) ii) strip( ) iii) rstrip( ) iv) lstrip( )
v) find( ) vi) rfind( ) vii) index( ) viii) rindex()
CSE-R-2019
R G M COLLEGE OF ENGINEERING & TECHNOLOGY, NANDYAL
AUTONOMOUS
COMPUTER SCIENCE AND ENGINEERING
ix) count( ) x) replace( ) xi) split( ) xii) join( )
xiii) upper( ) xiv) lower( ) xv) swapcase( ) xvi) title( )
xvii) capitalize( ) xviii) startswith() xix) endswith()
6 a) Python program to perform read and write operations on
a file.
b) Python program to copy the contents of a file to another
file.
c) Python program to count frequency of characters in a
given file.
d) Python program to print each line of a file in reverse
order.
e) Python program to compute the number of characters,
words and lines in a file.
7 a) Demonstrate the different ways of creating list objects
with suitable example programs.
b) Demonstrate the following functions/methods which
operates on lists in Python with suitable examples:
i) list( ) ii) len( ) iii) count( ) iv) index ( )
v) append( ) vi) insert( ) vii) extend() viii) remove( )
ix) pop( ) x) reverse( ) xi) sort( ) xii) copy( )
T
xiii) clear( )
c) Demonstrate the following with suitable example
programs:
i) List slicing
CE ii) List Comprehensions
8 a) Demonstrate the different ways of creating tuple objects
with suitable example programs.
b) Demonstrate the following functions/methods which
operates on tuples in Python with suitable examples:
i) len( ) ii) count( ) iii) index( ) iv) sorted( )
M
v) min ( ) vi)max( ) vii) cmp( ) viii) reversed( )
9 a) Demonstrate the different ways of creating set objects
with suitable example programs.
b) Demonstrate the following functions/methods which
operates on sets in Python with suitable examples:
RG
i) add( ) ii) update( ) iii) copy( ) iv) pop( )
v) remove( ) vi)discard( ) vii) clear( ) viii) union()
ix) intersection( ) x) difference( )
10 a) Demonstrate the different ways of creating dictionary
objects with suitable example programs.
b) Demonstrate the following functions/methods which
operates on dictionary in Python with suitable examples:
i) dict( ) ii) len( ) iii) clear( ) iv) get( )
v) pop( ) vi)popitem( ) vii) keys( ) viii) values()
ix) items( ) x) copy( ) xi) update( )
11 a) Demonstrate the following kinds of Parameters used
while writing functions in Python.
i) Positional Parameters ii) Default Parameters
iii)Keyword Parameters iv) Variable length Parameters
b) Write a Python program to return multiple values at a
time using a return statement.
c) Write a Python program to demonstrate Local and Global
variables.
d) Demonstrate lambda functions in Python with suitable
example programs.
12 Implement the following Searching and Sorting techniques
CSE-R-2019
R G M COLLEGE OF ENGINEERING & TECHNOLOGY, NANDYAL
AUTONOMOUS
COMPUTER SCIENCE AND ENGINEERING
in Python by using functions.
i) Linear Search ii) Binary Search
iii) Selection Sort iv) Bubble Sort
v) Insertion vi) Merge Sort
viii) Quick Sort
13 a) Demonstrate the following in-built functions to use
Regular Expressions very easily in our applications.
i) compile( ) ii) finditer( ) iii) match( ) iv) fullmatch( )
v) search( ) vi) findall( ) vii) sub( ) viii) subn( )
ix) split( )
b) Write a Regular Expression to represent all RGM
language (Your own language) identifiers.
Rules:
1. The allowed characters are a-z,A-Z,0-9,#.
2. The first character should be a lower case alphabet
symbol from a to k.
3. The second character should be a digit divisible by 3.
4. The length of identifier should be at least 2.
Write a python program to check whether the given string
T
is RGM language identifier or not?
c) Write a Regular Expression to represent all 10 digit
mobile numbers.
Rules:
CE
1. Every number should contains exactly 10 digits.
2. The first digit should be 7 or 8 or 9
Write a Python Program to check whether the given
number is valid mobile number or not?
M
TEXT BOOKS
RG
1. Learning Python, Mark Lutz, Orielly, 3 Edition 2007.
2. Python Programming: A Modern Approach, Vamsi Kurama, Pearson, 2017.
REFERENCE BOOKS
1) Think Python, 2 Edition, 2017 Allen Downey, Green Tea Press
2) Core Python Programming, 2016 [Link], Pearson.
3) Introduction to Python, 2015 Kenneth A. Lambert, Cengages
4) [Link]
5) [Link]