Course File Python
Course File Python
COURSE-FILE
Year / Semester : II/IV
Pragramming Practice(Python) CS-406
Department :Computer Sciences & Engineering
Academic Year : 2023-2024
Program : B.Tech
NAME OF FACULTY:
Issued by:
Prepared by: Approved By:
M2. To Practice and nurture high standards of human values, transparency and accountability.
M3. To collaborate with other academic and research institutes as well as industries in order to
strengthen education and research.
M4. To uphold skill development for employability and entrepreneurship for interdisciplinary
research and innovations.
To be a centre of excellence for providing quality technical education to develop future leaders
with the aspects of research &computing, Software product development and entrepreneurship.
M2: To conduct research and development activities in contemporary and emerging areas of
computer science & engineering.
M3: To inculcate moral values & entrepreneurial skills to produce professionals capable of
providing socially relevant and sustainable solutions.
Academic Calendar
Marks Policy
Attendance
Teacher Marks Total
Marks
Quiz Assignment Marks 5 5 10
Teacher Assessment
Attendance Marks Total
Marks
Lab Work/sessional Marks 15 5 20
Lab Work/sessional Marks (Language
10 10 20
Lab)
Practical Slot (10 + 10 Marks) for Workshop Practices/ Swachh Bharat Summer Internship Unnat Bharat
Abhiyan / Rural Outreach /Internship-I/II/III
Lab Work ( As-
Teacher Assess-
Attendance Marks signment /Quiz Total
ment Marks
etc.)
Lab Work Marks 5 NIL 5 10
Assignment Quiz /Term work Marks 5 5 NIL 10
Swachh Bharat Summer Internship Unnat 5
5 NIL 10
Bharat Abhiyan / Rural Outreach (MATHEMATICS)
Internship-I/BT107 40 MINIMUM
(as per I year internship 10 RANGE (30 50
training) TO 50 )
S. Theory Practical
Subject Term
No Subject Name
Code End Mid Sem. Quiz/ As- End
.
Sem. Exam. signment Sem. Lab W
Sess
BSC Mathematics- III
1. BT401 70 20 10 - -
2. DC Analysis Design of Algorithm 70 20 10 30 2
CS402
3. CS403 DC Software Engineering 70 20 10 30 2
4. DC Computer Org. & Architecture 70 20 10 30 2
CS404
5. CS405 DC Operating Systems 70 20 10 30 2
6. CS406 DLC* Programming Practices - - - 30 2
90 hrs Internship based on using
7. BT407 DLC various software’s –Internship -II To be completed anytime during fourth semester. Its evalua
Introduction: Basic syntax, Literal Constants, Numbers, Variable and Basic data types,
String, Escape Sequences, Operators and Expressions, Evaluation Order, Indentation, Input
Output, Functions, Comments.
Control Flow: Conditional Statements - If, If-else, Nested If-else. Iterative Statement -
For, While, Nested Loops. Control statements - Break, Continue, Pass.
Object oriented programming: Class and Object, Attributes, Methods, Scopes and Names-
paces, Inheritance, Overloading, Overriding, Data hiding.
Exception: Exception Handling, Except clause, Try finally clause, User Defined Excep-
tions.
Standard Libraries: File I/0, Sys, logging, Regular expression, Date and Time, Network
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Page 10
LAKSHMI NARAIAN COLLEGE OF TECHNOLOGY EXCELLENCE, BHOPAL
References
Rational
Unit 1
Python is a high-level, interpreted programming language known for its simplicity and readability. It was created by
Guido van Rossum and first released in 1991. Python emphasizes code readability and has a clean and easy-to-learn
syntax, which makes it an excellent language for beginners and professionals alike.
Simple and Readable Syntax: Python code is designed to be easy to read and write, which helps in reducing the cost of
program maintenance and development.
Interpreted and Interactive: Python is an interpreted language, meaning that you can run code line by line, making it
great for experimentation and rapid prototyping.
High-level Language: Python abstracts low-level details, making it easier to focus on the problem at hand rather than
managing system-level resources.
Dynamic Typing: Python uses dynamic typing, which means you don't need to declare the type of a variable explicitly.
The interpreter infers the type based on the value assigned to it.
Extensive Standard Library: Python comes with a vast standard library that provides support for various tasks like
string processing, file I/O, networking, and more, reducing the need for external libraries for many common tasks.
Cross-platform: Python is available on multiple platforms like Windows, macOS, and Linux, making it highly portable.
Object-Oriented: Python supports object-oriented programming (OOP) principles such as encapsulation, inheritance,
and polymorphism, making it suitable for building large-scale, modular applications.
Dynamically Typed: Python is dynamically typed, meaning you don't have to specify variable types. This can lead to
faster development times but may introduce runtime errors if not careful.
Basic Syntax:
Python syntax is relatively simple and easy to understand. Statements are typically terminated by a newline character,
but you can also use a semicolon (;) to separate multiple statements on a single line. Python uses indentation to define
blocks of code, rather than braces {} or keywords like begin and end
if True:
else:
Numbers:
Python supports integers, floating-point numbers, and complex numbers. You can perform arithmetic operations on
these numbers, such as addition, subtraction, multiplication, and division.
Variables in Python are dynamically typed, meaning you don't have to declare the type explicitly. You can assign any
value to a variable. Basic data types in Python include integers, floats, strings, booleans, lists, tuples, sets, and dictio-
naries.
Strings in Python are enclosed in either single (') or double (") quotes. Escape sequences are used to represent special
characters within strings, such as newline (\n), tab (\t), and backslash (\\).
Python supports various operators, including arithmetic operators (+, -, *, /, %), comparison operators (==, !=, <, >, <=,
>=), logical operators (and, or, not), and more.
Evaluation Order:
Expressions are evaluated following the usual mathematical rules, including precedence of operators (PEMDAS:
Parentheses, Exponents, Multiplication and Division, Addition and Subtraction).
Indentation:
Indentation is crucial in Python to define blocks of code, such as within loops, conditional statements, and function def-
initions. Consistent indentation using spaces or tabs is required, and mixing them can result in errors.
Input Output:
You can take input from the user using the input() function and display output using the print() function.
Functions:
Functions are defined using the def keyword. They allow you to encapsulate reusable pieces of code. Functions can
have parameters and return values.
Comments:
Comments in Python start with the # character and extend to the end of the line. They are used to document code and
improve its readability.
Unit 2
Lists:
A list is a mutable, ordered collection of items. Lists are defined using square brackets [] and can contain ele-
ments of different data types. You can modify, add, and remove elements from a
Tuples:
A tuple is an immutable, ordered collection of items. Tuples are defined using parentheses () and, like lists,
can contain elements of different data types. However, once a tuple is created, you cannot modify its elements. Here's
an example:
python
Copy code
Dictionary:
A dictionary is an unordered collection of items, consisting of key-value pairs. Dictionaries are defined using curly
braces {} and key-value pairs are separated by colons :. Keys must be unique and immutable (such as strings, integers,
or tuples), while values can be of any data type. Here's an example:
python
Copy code
Sets:
A set is an unordered collection of unique elements. Sets are defined using curly braces {} but without key-value pairs.
You can create a set from a list using the set() function. Sets support various set operations like union, intersection, dif-
ference, and symmetric difference. Here's an example:
python
Copy code
my_set = {1, 2, 3, 4, 5}
Unit 3
Conditional Statements:
Conditional statements in Python allow you to execute different blocks of code based on the evaluation of certain con-
ditions.
If Statement:
python
Copy code
x = 10
if x > 5:
If-else Statement:
The if-else statement allows you to execute one block of code if the condition is true and another block if the condition
is false.
python
Copy code
x = 10
if x > 5:
else:
You can nest if-else statements within each other to handle more complex conditions.
python
Copy code
x = 10
if x > 5:
if x > 8:
else:
else:
Iterative Statements:
For Loop:
The for loop is used to iterate over a sequence (such as a list, tuple, or string) or any iterable object.
python
Copy code
for i in range(5):
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Page 15
LAKSHMI NARAIAN COLLEGE OF TECHNOLOGY EXCELLENCE, BHOPAL
print(i)
While Loop:
The while loop is used to execute a block of code as long as the condition is true.
python
Copy code
x=0
while x < 5:
print(x)
x += 1
Nested Loops:
You can nest loops within each other to perform more complex iterations.
python
Copy code
for i in range(3):
for j in range(3):
print(i, j)
Control Statements:
Control statements allow you to alter the flow of execution within loops or conditional statements.
Break Statement:
python
Copy code
for i in range(5):
if i == 3:
break
print(i)
Continue Statement:
The continue statement is used to skip the current iteration and proceed to the next iteration of the loop.
python
Copy code
for i in range(5):
if i == 3:
continue
print(i)
Pass Statement:
The pass statement is a null operation, meaning it does nothing. It can be used as a placeholder when a statement is
syntactically required but you don't want any code to execute.
python
Copy code
x = 10
if x > 5:
else:
These are the basic control flow constructs in Python that allow you to make decisions, iterate over sequences, and con-
trol the flow of execution within your code.
Unit 4
A class is a blueprint for creating objects. It defines the attributes and behaviors that objects of the class will
have.
An object is an instance of a class. It represents a specific entity with its own unique state and behavior.
python
Copy code
class MyClass:
pass
Attributes:
Attributes are the properties or characteristics associated with a class or object. They can be variables (data
attributes) or functions (methods).
python
Copy code
class Person:
Methods:
Methods are functions defined within a class. They define the behavior of objects of the class.
Methods can operate on the object's attributes and modify their state.
python
Copy code
class Circle:
self.radius = radius
def area(self):
circle1 = Circle(5)
A namespace is a mapping from names to objects. It organizes the names defined within a Python program.
Python uses the LEGB rule (Local, Enclosing, Global, Built-in) to determine the scope of a name.
Inheritance:
Inheritance allows a class (subclass) to inherit attributes and methods from another class (superclass).
It promotes code reusability and supports the creation of hierarchical relationships between classes.
python
Copy code
class Animal:
def speak(self):
print("Animal speaks")
def bark(self):
print("Dog barks")
dog = Dog()
Overloading:
Overloading allows a class to define multiple methods with the same name but different parameters or
behaviors.
Python does not support method overloading by default, but you can achieve it using default parameter
values or variable arguments.
Overriding:
Overriding occurs when a subclass provides a specific implementation of a method that is already defined in
its superclass.
The overridden method in the subclass replaces the implementation of the same method in the superclass.
Data Hiding:
Data hiding (encapsulation) is the process of restricting access to certain attributes or methods of a class.
It helps to prevent accidental modification of data and ensures that access to attributes and methods is
controlled.
python
Copy code
class MyClass:
def __hidden_method(self):
obj = MyClass()
These concepts form the foundation of object-oriented programming in Python, enabling you to create
modular, reusable, and maintainable code.
Unit 5
Exception handling is a crucial aspect of programming to deal with unexpected errors or exceptional situations. Python
provides several constructs for exception handling:
Try-Except Clause:
The try-except block allows you to handle exceptions gracefully by catching and responding to specific types of errors.
python
Copy code
try:
except ZeroDivisionError:
Try-Finally Clause:
The try-finally block ensures that certain code (usually cleanup code) runs regardless of whether an exception occurs or
not.
python
Copy code
try:
finally:
You can create custom exception classes by subclassing built-in exception classes or the Exception class.
python
Copy code
class CustomError(Exception):
pass
try:
x = 10
if x > 5:
raise CustomError("x should not be greater than 5") # Raise custom exception
except CustomError as e:
Exception Hierarchy:
Python's exceptions are organized in a hierarchy. You can catch exceptions at different levels of this hierarchy, from
more specific exceptions to more general ones.
python
Copy code
try:
except ValueError:
# Handle ValueError
except FileNotFoundError:
# Handle FileNotFoundError
except Exception:
You can use multiple except clauses to catch different types of exceptions in the same try block.
python
Copy code
try:
x = 10 / 0
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Page 21
LAKSHMI NARAIAN COLLEGE OF TECHNOLOGY EXCELLENCE, BHOPAL
except ZeroDivisionError:
print("Division by zero")
except ValueError:
print("Invalid value")
You can access information about the exception using the as keyword.
python
Copy code
try:
x = 10 / 0
except ZeroDivisionError as e:
Exception handling in Python allows you to write robust and fault-tolerant code by gracefully handling errors and fail-
ures. It's essential for writing reliable software that can handle unexpected situations without crashing.
Blooms Taxonomy
PSO2: An ability to develop programming skills using modern software tools and techniques.
PSO3: An ability to develop real time projects for problem solving of domains such as Machine
PSO2 An ability to develop programming skills using modern software tools and techniques.
An ability to develop real time projects for problem solving of domains such as Machine learning Cyber
PSO3
security, block chain and big data.
An ability to grab research, higher studies and entrepreneurship opportunities towards society with moral
PSO4
values and ethics.
CO/PSO Matrix
CO/PSO PSO1 PSO2 PSO3 PSO4
CO406.1 - 2 3 3
CO406.2 - 2 3 3
CO406.3 - 2 3 3
CO406.4 - 2 3 3
CO406.5 - 3 3 3
- 2.2 3 3
List of Experiment
Date Of Implementation
List of Experiment
S. No.
Expected CO Remark
Actual date
date Covered
Practical Performance/ Either the student is The student per- The student per- The student
Absent in all lab ses- formed almost 25 formed almost 50 formed 75 % o
Teacher’s Assessment sions or performed % of practical % of practical tical success
(10) less than 25% of successfully. successfully.
practical or the per-
formance was
not successful.
Practical Quiz/Assign- Either the student is The student’s score is The student’s score is The student’s s
ment (5) Absent or the re- between 01 to 25 %. between 26 to 50 %. between 51 to
sponse is not avail-
able/
incomplete.
Attendance (5) Student’s attendance Student’s attendance Student’s attendance Student’s atten
is below 40 %. is between 40 % and is between 50 % and is between 60
50 %. 59 %. 74 %.
End Semester Exami- Grade F represents Grade D represents Grade C + represents Grade B + rep
nation (100) marks between 30 - marks between 31-40 marks between 51-60 marks between
0 and performance is and performance is and performance is and performa
Grade Fail Marginal Average Very Goo
%Marks range (based Grade I represents
on absolute marks sys- Incomplete. Grade C represents Grade B repr
tem) Grade W represents marks between 41-50 marks between
Description of and performance is and performa
Withdrawal
performance) Satisfactory Good