CST 445 Python For Engineers - Open Elective

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

COMPUTER SCIENCE AND ENGINEERING

YEAR OF
PYTHON FOR CATEGORY L T P CREDIT INTRODUCTION
CST445 ENGINEERS
OEC 2 1 0 3 2019

Preamble: The objective of the course is to provide learners an insight into Python programming
in a scientific computation context and develop programming skills to solve engineering
problems. It covers programming environment, important instructions, data representations,
intermediate level features, Object Oriented Programming and file data processing of Python.
This course lays the foundation to scientific computing, develop web applications, Machine
Learning, and Artificial Intelligence-based applications and tools, Data Science and Data
Visualization applications.

Prerequisite: NIL

Note : Students who have successfully completed CST 283 - Python for Machine Learning
(Minor) are not eligible to opt this course.
Course Outcomes: After the completion of the course the student will be able to

Write, test and debug Python programs (Cognitive Knowledge level:


CO1
Apply)
Illustrate uses of conditional (if, if-else, if-elif-else and switch-case) and
CO2 iterative (while and for) statements in Python programs (Cognitive
Knowledge level: Apply)
Develop programs by utilizing the modules Lists, Tuples, Sets and
CO3
Dictionaries in Python (Cognitive Knowledge level: Apply)
Implement Object Oriented programs with exception handling (Cognitive
CO4
Knowledge level: Apply)
Analyze, Interpret, and Visualize data according to the target application (Cognitive
CO5
Knowledge level: Apply)
Develop programs in Python to process data stored in files by utilizing the modules
CO6
Numpy, Matplotlib, and Pandas (Cognitive Knowledge level: Apply)
COMPUTER SCIENCE AND ENGINEERING

Mapping of course outcomes with program outcomes

PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12

CO1

CO2

CO3

CO4

CO5

CO6

Abstract POs defined by National Board of Accreditation

#PO Broad PO #PO Broad PO


PO1 Engineering Knowledge PO7 Environment and Sustainability
PO2 Problem Analysis PO8 Ethics
PO3 Design/Development of solutions PO9 Individual and team work
PO4 Conduct investigations of complex problems PO10 Communication
PO5 Modern tool usage PO11 Project Management and Finance
PO6 The Engineer and Society PO12 Life long learning

Assessment Pattern
Test 1 (Marks in Test 2 (Marks End Semester
Bloom’s Category
percentage) in percentage) Examination Marks
Remember 20 20 20
Understand 30 30 30
Apply 50 50 50
Analyse
Evaluate
Create

Mark Distribution

Total Marks CIE Marks ESE Marks ESE Duration


150 50 100 3
COMPUTER SCIENCE AND ENGINEERING

Continuous Internal Evaluation Pattern:


Attendance : 10 marks
Continuous Assessment Test : 25 marks
Continuous Assessment Assignment : 15 marks

Internal Examination Pattern:


Each of the two internal examinations has to be conducted out of 50 marks. The first series test
shall be preferably conducted after completing the first half of the syllabus and the second series
test shall be preferably conducted after completing the remaining part of the syllabus. There will
be two parts: Part A and Part B. Part A contains 5 questions (preferably, 2 questions each from
the completed modules and 1 question from the partly completed module), having 3 marks for
each question adding up to 15 marks for part A. Students should answer all questions from Part
A. Part B contains 7 questions (preferably, 3 questions each from the completed modules and 1
question from the partly completed module), each with 7 marks. Out of the 7 questions, a student
should answer any 5.

End Semester Examination Pattern:


There will be two parts; Part A and Part B. Part A contains 10 questions with 2 questions from
each module, having 3 marks for each question. Students should answer all questions. Part B
contains 2 questions from each module of which a student should answer any one. Each question
can have a maximum of 2 sub-divisions and carries 14 marks.

Syllabus
Module 1 (Basics of Python)
Getting Started with Python Programming - Running code in the interactive shell, Editing,
Saving, and Running a script. Using editors - IDLE, Jupyter. Basic coding skills - Working with
data types, Numeric data types and Character sets, Keywords, Variables and Assignment
statement, Operators, Expressions, Working with numeric data, Type conversions, Comments in
the program, Input Processing, and Output, Formatting output. How Python works. Detecting
and correcting syntax errors. Using built in functions and modules in math module. Control
statements - Selection structure - if-else, if-elif-else. Iteration structure - for, while. Testing the
control statements. Lazy evaluation.

Module 2 (Functions and Python Data Structures)


Functions - Hiding redundancy and complexity, Arguments and return values, Variable scopes
and parameter passing, Named arguments, Main function, Working with recursion, Lambda
functions. Strings - String function. Lists - Basic list Operations and functions, List of lists,
Slicing, Searching and sorting list, List comprehension. Work with tuples. Sets. Dictionaries -
Dictionary functions, dictionary literals, adding and removing keys, accessing and replacing
values, traversing dictionaries, reverse lookup.
COMPUTER SCIENCE AND ENGINEERING

Module 3 (Object Oriented Programming)


Design with classes - Objects and Classes, Methods, Instance Variables, Constructor, Accessors
and Mutators. Structuring classes with Inheritance and Polymorphism. Abstract Classes.
Exceptions - Handle a single exception, Handle multiple exceptions.

Module 4 (Visualization and File handling)


Plotting - An Interactive Session with PyPlot, Basic Plotting, Logarithmic Plots, More Advanced
Graphical Output, Plots with multiple axes, Mathematics and Greek symbols, The Structure of
matplotlib, Contour and Vector Field Plots. File Processing - The os and sys modules,
Introduction to file I/O, Reading and writing text files, Working with CSV files.

Module 5 (Scientific Computing)


Numerical Routines. SciPy and NumPy - Basics, Creating arrays, Arithmetic, Slicing, Matrix
Operations, Special Functions, Random Numbers, Linear Algebra, Solving Nonlinear Equations,
Numerical Integration, Solving ODEs. Data Manipulation and Analysis – Pandas : Reading Data
from Files Using Pandas, Data Structures: Series and DataFrame, Extracting Information from a
DataFrame, Grouping and Aggregation.

Text Books:
1. Kenneth A Lambert., Fundamentals of Python : First Programs, 2/e, Cengage Publishing, 2016
2. David J. Pine, Introduction to Python for Science and Engineering, CRC Press, 2021

Reference Books:
1. Wes McKinney, Python for Data Analysis, 2/e, Shroff / O’Reilly Publishers, 2017
2. Allen B. Downey, Think Python: How to Think Like a Computer Scientist, 2/e, Schroff, 2016
3. Michael Urban and Joel Murach, Python Programming, Shroff/Murach, 2016
4. David M.Baezly, Python Essential Reference. Addison-Wesley Professional; 4/e, 2009.
5. Charles Severance. Python for Informatics: Exploring Information,
6. http://swcarpentry.github.io/python-novice-gapminder/

Sample Course Level Assessment Questions

Course Outcome1(CO1):
1. What is type conversion? How is it done in Python?

Course Outcome 2(CO2):


1. Given is a list of of words, wordlist, and a string, name. Write a Python function which
takes wordlist and name as input and returns a tuple. The first element of the output
tuple is the number of words in the wordlist which have name as a substring in it. The
second element of the tuple is a list showing the index at which the name occurs in each
of the words of the wordlist and a 0 if it doesn’t occur.
COMPUTER SCIENCE AND ENGINEERING

Course Outcome 3(CO3):


1. Write a Python program to implement the addition, subtraction, and multiplication of
complex numbers using classes. Use constructors to create objects. The input to the
program consist of real and imaginary parts of the complex numbers.

Course Outcome 4(CO4):


1. Plot the function y = 3x2 for −1 ≤ x ≤ 3 as a continuous line. Include enough points so
that the curve you plot appears smooth. Label the axes x and y

Course Outcome 5(CO5):


1. Given a file “auto.csv” of automobile data with the fields index, company, body-style,
wheel-base, length, engine-type, num-of-cylinders, horsepower, average-mileage, and
price, write python code to
i. Clean and Update the CSV file
ii. Print total cars of all companies
iii. Find the average mileage of all companies
iv. Find the highest priced car of all companies.

Model Question Paper


QP CODE: PAGES:

Reg No:_______________
Name:_________________

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY


SEVENTH SEMESTER B.TECH DEGREE EXAMINATION, MONTH & YEAR
Course Code: CST445
Course name : PYTHON FOR ENGINEERS
Max Marks: 100 Duration: 3 Hours
PART-A
(Answer All Questions. Each question carries 3 marks)

1. Explain the basic data types available in Python, with examples.


Write a Python program to reverse a number and also find the sum of digits of the number.
2.
Prompt the user for input.
3. Compare tuples, lists, and dictionaries.
Explain the concept of scope and lifetime of variables in Python programming language,
4.
with a suitable example.
5. What is polymorphism? Give an example in the context of OOP in Python.
6. How is exception handling accomplished in Python programs?
7. Describe the characteristics of the CSV format.
COMPUTER SCIENCE AND ENGINEERING

Plot the function y = 3x2 for −1 ≤ x ≤ 3 as a continuous line. Include enough points so that
8.
the curve you plot appears smooth. Label the axes x and y
9. Describe random number generation using Python
10. How can a generalized eigen value problem can be solved using Python?

PART-B
(Answer any one full question from each module)
Module -1
11. (a) Compare and contrast interpreted languages and compiled languages. (6)
How does it affect the quality of program development and execution of
the program?
(b) What are the possible errors in a Python program. Write a Python (8)
program to print the value of 22n+n+5 for n provided by the user.
OR
12. (a) Describe Arithmetic operators, Assignment operators, Comparison (6)
operators, Logical operators, and Bitwise operators in detail with examples.
(b) Input 4 integers (+ve and −ve). Write a Python code to find the sum of (8)
negative numbers, positive numbers, and print them. Also, find the averages
of these two groups of numbers and print
Module -2
13. (a) Write a Python code to create a function called list_of_frequency that takes a (5)
string and prints the letters in non-increasing order of the frequency of their
occurrences. Use dictionaries.
(b) Write a Python program to read a list of numbers and sort the list in a non- (9)
decreasing order without using any built in functions. Separate function
should be written to sort the list wherein the name of the list is passed as the
parameter.
OR
14. (a) Illustrate the following Set methods with an example. (8)
i. intersection( ) ii. Union( ) iii. Issubset( ) iv. Difference( ) v. update( ) vi.
discard( )
(b) Write a Python program to check the validity of a password given by the (6)
user.
The Password should satisfy the following criteria:
1. Contains at least one letter between a and z
2. Contains at least one number between 0 and 9
3. Contains at least one letter between A and Z
COMPUTER SCIENCE AND ENGINEERING

4. Contains at least one special character from $, #, @


5. Minimum length of password: 6
Module -3
15. (a) How can a class be instantiated in Python? Write a Python program to (5)
express the instances as return values to define a class RECTANGLE with
parameters height, width, corner_x, and corner_y and member functions to
find center, area, and perimeter of an instance.
(b) Explain inheritance in Python. Give examples for each type of inheritance. (9)
OR
16. (a) Write a Python class named Circle constructed by a radius and two methods (6)
which will compute the area and the perimeter of a given circle
(b) Define a class in Python to store the details of a ship (name, (8)
source,destination) with the following methods:
i) get_details( ) - to assign values to class attributes
ii) print_details( ) - to display the attribute values
Create an object of the class and invoke the methods
Module -4
17. (a) Plot the functions sin x and cos x vs x on the same plot with x going from −π (10)
to π. Make sure the limits of the x-axis do not extend beyond the limits of
the data. Plot sin x in the color orange and cos x in the color green and
include a legend to label the two curves. Place the legend within the plot,
but such that it does not cover either of the sine or cosine traces. Draw thin
gray lines behind the curves, one horizontal at y = 0 and the other vertical at
x = 0.
(b) Explain semi-log plots and log-log plots along with the functions used in (4)
creating such plots.
OR
18. (a) Explain how matplotlib can be used to create dimensional contour plots and (6)
vector field plots.
(b) Given a file “auto.csv” of automobile data with the fields index, company, (8)
body-style, wheel-base, length, engine-type, num-of-cylinders, horsepower,
average-mileage, and price, write Python codes using Pandas to
1) Clean and Update the CSV file
2) Print total cars of all companies
3) Find the average mileage of all companies
4) Find the highest priced car of all companies.
COMPUTER SCIENCE AND ENGINEERING

Module -5
19. (a) Write python program to solve the following system of equations (4)
x1 − 2x2 + 9x3 + 13x4 = 1
−5x1 + x2 + 6x3 − 7x4 = −3
4x1 + 8x2 − 4x3 − 2x4 = −2
8x1 + 5x2 − 7x3 + x4 = 5
(b) Given the sales information of a company as CSV file with the following (10)
fields month_number, facecream, facewash, toothpaste, bathingsoap,
shampoo, moisturizer, total_units, total_profit. Write Python codes to
visualize the data as follows
1) Toothpaste sales data of each month and show it using a scatter plot
2) Face cream and face wash product sales data and show it using the
bar chart
Calculate total sale data for last year for each product and show it using a
Pie chart.
OR
20. (a) Write Python program to write the data given below to a CSV file. (9)
SN Name Country Contribution Year

1 Linus Torvalds Finland Linux Kernel 1991

2 Tim Berners-Lee England World Wide Web 1990

3 Guido van Rossum Netherlands Python 1991

(b) Explain how integration is performed with SciPy. Illustrate the same with (5)
the two sample integrals using SciPy function.
COMPUTER SCIENCE AND ENGINEERING

Teaching Plan
Number of
Sl
Contents Hours (35
No
Hrs)
Module 1: Basics of Python (8 hours)
Getting Started with Python Programming: Running code in the interactive
1.1 1 hour
shell Editing, Saving, and Running a script
1.2 Using editors: IDLE, Jupyter 1 hour
Basic coding skills: Working with data types, Numeric data types and
1.3 Character sets, Keywords, Variables and Assignment statement, Operators, 1 hour
Expressions,
Working with numeric data, Type conversions, Comments in the program,
1.4 1 hour
Input Processing, and Output. Formatting output
How Python works. Detecting and correcting syntax errors. Using built in
1.5 1 hour
functions and modules in math module.
1.6 Control statements : Selection structure, if-else, if elifelse 1 hour
1.7 Iteration structure - for, while 1 hour
1.8 Testing the control statements, Lazy evaluation. 1 hour
Module 2: Functions and Python Data Structures (8 hours)
2.1 Functions: Hiding redundancy and complexity, Arguments and return values 1 hour
2.2 Variable scopes and parameter passing 1 hour
2.3 Named arguments, Main function, 1 hour
2.4 Working with recursion, Lambda functions 1 hour
2.5 Strings - String function 1 hour
Lists - Basic list Operations and functions, List of lists, Slicing, Searching
2.6 1 hour
and sorting list, List comprehension.
2.7 Work with tuples. Sets. 1 hour
Dictionaries - Dictionary functions, dictionary literals, adding and removing
2.8 1 hour
keys, Accessing and replacing values, traversing dictionaries, reverse lookup
Module 3: Object Oriented Programming (6 hours)
3.1 Design with classes : Objects and Classes, Methods, Instance Variables 1 hour
3.2 Constructor, Accessors, and Mutators 1 hour
3.3 Structuring classes with Inheritance 1 hour
3.4 Polymorphism 1 hour
3.5 Abstract Classes 1 hour
3.6 Exceptions: Handle a single exception, Handle multiple exception 1 hour
Module 4: Visualization and File handling (6 hours)
COMPUTER SCIENCE AND ENGINEERING

4.1 Plotting - An Interactive Session with PyPlot, Basic Plotting, 1 hour


4.2 Logarithmic Plots, More Advanced Graphical Output 1 hour
4.3 Plots with multiple axes, Mathematics and Greek symbols 1 hour
4.4 The Structure of matplotlib, Contour and Vector Field Plots 1 hour
File Processing -The os and sys modules, Introduction to file I/O, Reading
4.5 1 hour
and writing text files
4.6 Working with CSV files 1 hour

Module 5: Scientific Computing (7 hours)


Numerical Routines: SciPy and NumPy - Basics, Creating arrays,
5.1 1 hour
Arithmetic, Slicing
5.2 Matrix Operations, Special Functions, Random Numbers 1 hour
5.3 Linear Algebra, Solving Nonlinear Equations 1 hour
5.4 Numerical Integration, Solving ODEs 1 hour
Data Manipulation and Analysis: Pandas - Reading Data from Files Using
5.5 1 hour
Pandas
5.6 Data Structures - Series and DataFrame 1 hour
5.7 Extracting Information from a DataFrame, Grouping and Aggregation 1 hour

You might also like