Department COMPUTER SCIENCE AND ENGINEERING R2024 Semester II
Hours/
Credit Total Maximum
Course Code Course Name Week
Hours Marks
L T P C
PYTHON PROGRAMMING
24ADI201 3 0 2 4 75 100
(Common to Civil/ECE/EEE/Mechanical)
Course Objectives
The objective of this course is to
• learn the basic Python Syntax, Data Types and operators
• understand the various decision and control flow statements in Python programming
• develop a proficiency in handling functions and processing lists and strings
• understand and use tuples and dictionaries
• learn to perform file operations and explore the Python Standard Library
UNIT I INTRODUCTION TO PYTHON 9
Introduction to Python, Python Identifiers, Keywords and Indentation, – variables Comments. Data types in Python
(Boolean, integer, float, complex numbers, list, string, tuples, and dictionary) Mutable vs Immutable variables,
Namespaces, dynamic typing vs static typing. Operators and expressions, Precedence and Associativity. Input/output
statements, Illustrative programs.
UNIT II CONTROL FLOW AND FUNCTIONS 9
Decision Statements: Boolean Type, Boolean Operators, if statement, else statement, Nested Conditionals
Statements, Multi-way Decision Statements (elif statement). Illustrative programs. Control Statements: While loop,
range () Function, For Loop, Nested Loops, Infinite Loop, Break Statement, Continue Statement, pass Statement.
Illustrative programs. Function: Function definition - return values, Actual and Formal Parameters, parameters
passing (pass by value and reference), anonymous (lambda) function – Global and Local Variables, recursion,
generator functions. Illustrative programs.
UNIT III LISTS AND STRINGS 9
Lists: declaration, Indexing, accessing, - list operators [+, *, :, slices], Identity and Membership operators, list built-
in functions, list methods, list traversals – list comprehension, List Processing : Searching and Sorting, Illustrative
programs. String: Declaration, Accessing-immutability-string operators [+, *, :, slices], Identity and Membership
operators, string built-in functions, string methods, string module. Illustrative programs.
UNIT IV TUPLES AND DICTIONARIES 9
Tuples: immutability, tuple creation, tuple built-in functions, tuple methods, Tuple Assignment tuple as return value.
Illustrative programs. Dictionary: declaration – concepts of key-value pairs – types of keys-various Initializations -
Dictionary built-in functions, Dictionary methods. Illustrative programs.
UNIT V FILES, PYTHON LIBRARIES AND MODULES 9
Files: Types of files (text and binary), File operations (open, read, write, append, close) - Example Programs. Python
Standard Library, Built-in modules, Exploring commonly used modules and packages.
Suggested Modules:
Module itertools (permutations, combinations, product)
Module random (randrange, randint, choice, shuffle, random)
Module (sqrt(), floor(), ceil(), exp(), log(), pi, Date and time
TOTAL : 45 Periods
PRACTICAL EXCERCISES
1. Print the sum of the digits of a number in alternative positions
2. Generate prime numbers till the given n value
3. Check whether the given number is an Armstrong number or not
4. Design a scientific calculator(+,-,^,*,/) until the last number is given
Input: 5^3*3+6*7-9-2+3^2 Output: 415
5. Find the second largest number from the given 7 digit number
Input:8740392 Output:9874320
6. Perform the swapping of 2 numbers to sort the given array
Input:[5,1,6,7,9,0] Output:[0,1,5,6,7,9]
7. Generate Fibonacci series till n numbers with and without using recursion
Department of Civil Engineering – R 2024 Page 46 of 94
8. Capitalize the first letter of the word in a sentence
Input: india is a biggest nation Output: India Is A Biggest Nation
9. Find the largest occurrence of the character in a String using dictionary
Input: Apple Output: p
10. Get an input from the user and save it in a file using write mode. Open the file in read mode and copy the
text from one file to another file
11. Count the number of characters, words and lines in a file
12. Print the Student Mark list using Modules
Total : 30 Periods
List of Equipment:(30 Students per Batch)
Tools: Python, Numpy
Note: Jupyter Notebook, Spyder, Google Colab may also be used.
Text Book(s)
1. Allen B. Downey, Think Python: How to Think Like a Computer Scientist, 2nd edition, Updated for Python 3,
Shroff/O’Reilly Publishers, 2016.
Reference(s)
1. Jake Vanderplas, Python Data Science Handbook: Essential Tools for Working with Data, 1st Edition, O'Reilly
Media, 2016.
2. Eric Matthes, “Python Crash Course, A Hands - on Project Based Introduction to Programming”, 2nd Edition,
No Starch Press, 2019.
3. Martin C. Brown, “Python: The Complete Reference”, 4th Edition, Mc-Graw Hill, 2018.
4. [Link]
Course Outcomes
At the end of this course, students will be able to:
CO1 develop simple computational problems using python operators and data types
CO2 provide solutions for basic analytical problems using decision and control flow statements
CO3 use Functions and apply List and String operations in Python with and without built-in functions
CO4 apply the properties of tuples and dictionaries in Python
CO5 design Python code to explore the file operations
Alternative NPTEL/SWAYAM Course:
[Link] NPTEL Course Name
1. Programming in Python
2. Python for Data Science
3. The Joy of Computing using Python
Experiments that may be performed using Virtual Labs through the following Links:
Experiments 1-12 1. [Link]
Department of Civil Engineering – R 2024 Page 47 of 94
CO-PO / PSO Mapping
CO-
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
PO/PSO
CO1 3 3 3 3 3 - - - - - 2 2 - - -
CO2 3 3 3 2 3 - - - - - 2 2 - - -
CO3 3 3 3 2 3 - - - - - 2 2 - - -
CO4 3 3 3 2 3 - - - - - 2 2 - - -
CO5 3 3 3 2 3 - - - - - 2 2 - - -
CO Avg. 3 3 3 2.2 3 - - - - - 2 2 - -
Contribution: 1. Low, 2. Medium, 3. High
Department of Civil Engineering – R 2024 Page 48 of 94