PET ENGINEERING COLLEGE
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
AD25201-PYTHON FOR DATA SCIENCE
Date: 25/02/2026 (AN) Internal Assessment Test I Time : 90 mts
Sem: S2 [Link]/ AI&DS Max Marks: 50
Answer key
PART- A (5 x 2 = 10 Marks)
Write the purpose of break and continue statement
1.
The break statement is used to immediately stop a loop when a certain condition is met.
When break is executed, the program exits the loop and continues with the next statement
after the loop.
The continue statement is used to skip the current iteration of the loop and move to the next
2
iteration.
2. What is the difference between list, tuple, dictionary
A list stores multiple items in a single variable and can be modified.
A tuple is similar to a list but cannot be changed after creation.
A dictionary stores data in key–value pairs.
2
3. Explain the Seek() and methods used in python file handling
Seek():
The seek() method changes the current position of the file pointer. 2
0 → Beginning of the file (default)
1 → Current position
2 → End of the file
4 Write python script to display current date & time
From datetime import datetime
# get current date and time 2
now = [Link]()
# display date and time
print("Current Date and Time:", now)
5 What is data science and state any two applications of data science
Data Science is an interdisciplinary field that uses scientific methods, algorithms, and
systems to analyze and extract useful information from data. It combines statistics, programming, and 2
domain knowledge to find patterns and make better decisions.
Applications of Data Science:
Healthcare: Data science helps in disease prediction, medical image analysis, and
improving patient treatment.
Business and Marketing: Companies analyze customer data to understand buying behavior
and improve sales strategies.
Part – B (2 x 13 = 26 marks)
Answer the following Marks
6. a) Explain Control Structures in Python with Example.
Control structures are used to control the flow of execution of a program. Normally, Python 2
executes statements sequentially from top to bottom. However, sometimes it is necessary to
change the order of execution depending on conditions or to repeat certain tasks multiple
times. Control structures make this possible.
Control structures in Python are mainly classified into three types:
Sequential Control Structure
Selection (Decision Making) Control Structure
Iteration (Looping) Control Structure
1. Sequential Control Structure
In sequential control structure, statements are executed one after another in the order they 2
appear in the program.
Example:
a = 10
b = 20
c=a+b
print("Sum:", c)
Here, each statement is executed in sequence. This is the simplest form of program execution.
2. Selection Control Structure 5
Selection control structure allows the program to make decisions based on conditions. It
executes different statements depending on whether the condition is true or false.
Python provides the following selection statements:
if statement
if–else statement
if–elif–else statement
a) if Statement
The if statement executes a block of code only when the condition is true.
Example:
x = 15
if x > 10:
print("x is greater than 10")
b) if–else Statement
The if–else statement executes one block if the condition is true and another block if it is false.
Example:
num = 8
if num % 2 == 0:
print("Even Number")
else:
print("Odd Number")
c) if–elif–else Statement
This statement is used when there are multiple conditions to check.
Example:
marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 70:
print("Grade B")
else:
print("Grade C")
3. Iteration Control Structure
Iteration means repeating a block of code multiple times. Python provides loops to perform 4
iteration.
Types of loops in Python:
for loop
while loop
a) for Loop
The for loop is used to iterate over a sequence such as list, tuple, or range.
Example:
for i in range(2):
print(i)
Output:0 1
while Loop
The while loop executes a block of code as long as the condition is true.
Example:
i=1
while i <= 5:
print(i)
i=i+1
Loop Control Statements
Python also provides special statements to control loop execution:
Break
Stops the loop immediately.
for i in range(5):
if i == 3:
break
print(i)
Continue
Skips the current iteration and moves to the next iteration.
for i in range(5):
if i == 2:
continue
print(i)
Explain Python Tokens(keywords, literals, identifiers, operators)
6. b) 1
Python tokens are the smallest units of a Python program. A Python program is made
up of different tokens such as keywords, identifiers, literals, and operators. These tokens are
used by the Python interpreter to understand and execute the program.
Example:
a = 5 + 10
Tokens in this program are: a ,= ,5 ,+ ,1 ,0
Python tokens are classified into four main types:
Keywords
Identifiers
Literals
Operators
1. Keywords
Keywords are reserved words that have special meaning in Python. These words cannot be 3
used as variable names.
Examples of Python keywords:
If ,else ,while ,for ,break ,continue ,return ,class ,try ,except
Example:
if x > 5:
print("Greater")
Here if is a keyword used for decision making.
2. Identifiers 3
Identifiers are names used to identify variables, functions, classes, or objects.
Example program:
name = "Arun"
marks = 85
print(name)
Rules for identifiers:
Must start with a letter or underscore
Cannot start with a number
Cannot be a keyword
Must not contain special characters
3. Literals
Literals are constant values used in a program. 3
Types of literals:
Numeric Literal
Example:10 20 3.14
String Literal
Example:"Python" 'Data Science'
Boolean Literal
a = 10
name = "Python"
flag = True
4. Operators
Operators are symbols used to perform operations on variables.
Types of operators:
Arithmetic Operators + - * / % 3
Example:
a = 10
b=5
print(a + b)
Relational Operators > < == !=
print(a > b)
Logical Operators :and or not
Example:
if a > 5 and a < 20
print("Valid number")
Python tokens form the basic building blocks of a Python program. Understanding
tokens such as keywords, identifiers, literals, and operators helps programmers write correct
and efficient Python programs.
7. a) Explain the Types of Files and File Operations
A file is a collection of data stored on a storage device. Files are used to store data 2
permanently so that it can be accessed later. Python provides built-in functions to create, read,
write, and manipulate [Link] in Python are mainly classified into two types.
Types of Files
1. Text Files
2
Text files store data in human-readable format. The data is stored as characters.
Examples: .txt, .csv, .log
Example of text file content:
Name: Arun
Age: 20
Department: AI & DS
2. Binary Files
Binary files store data in binary format (0 and 1). These files are not readable by humans
2
directly.
Examples:
.dat
.bin
.exe
Binary files are used to store images, audio, video, etc.
File Operations in Python 7
Python supports several operations on files.
Opening a file
Reading a file
Writing to a file
Closing a file
1. Opening a File
A file is opened using the open() function.
Syntax:
file = open("filename", "mode")
Modes:
r – read w – write a – append
f = open("[Link]", "r")
2. Reading a File
Python provides several methods to read data from a file.
Methods:read()
readline()
readlines()
Example:
f = open("[Link]", "r")
print([Link]())
[Link]()
3. Writing to a File
Data can be written to a file using the write() method.
f = open("[Link]", "w")
[Link]("Welcome to Python Programming")
[Link]()
4. Closing a File
After completing file operations, the file must be closed using close().
[Link]()
Closing the file releases system resources.
File handling is an important feature in Python that allows programs to store and retrieve
data from files. Using different file operations such as open, read, write, and close, data can
be managed effectively.
Define Exception and explain the methods to handle exception with example.
7. b) 3
An exception is an error that occurs during the execution of a program. When an
exception occurs, it interrupts the normal flow of the program. Exception handling is used to
detect and handle errors so that the program continues to execute smoothly.
Common Types of Exceptions
ZeroDivisionError
TypeError
ValueError
FileNotFoundError
Example:
a = 10
b=0
print(a/b) 10
This produces ZeroDivisionError.
Exception Handling Keywords
Python provides the following keywords:
try
except
finally
Try Block
The try block contains code that might cause an exception.
Example:
try:
a = 10
b=0
c=a/b
Except Block
The except block handles the error.
Example:
except ZeroDivisionError:
print("Division by zero is not allowed")
Finally Block
The finally block executes whether an error occurs or not.
Example:
finally:
print("Program finished")
Example Program
try:
num1 = int(input("Enter number: "))
num2 = int(input("Enter number: "))
result = num1 / num2
print(result)
except ZeroDivisionError:
print("Cannot divide by zero")
except ValueError:
print("Invalid input")
finally:
print("Execution completed")
Advantages
Prevents program crash
Improves program reliability
Helps handle runtime errors
PART C(1x14=14)
Explain in detail about Exploratory Data Analysis (EDA)
8. a) 2
Exploratory Data Analysis (EDA) is the process of analyzing and summarizing datasets to
understand their structure and patterns before applying machine learning or statistical models.
EDA helps data scientists understand the dataset and identify important characteristics.
Steps in EDA:
1. Data Collection 4
Data is collected from various sources such as:
Databases
CSV files
Web APIs
2. Data Cleaning
Data cleaning removes errors and inconsistencies.
Examples:
Handling missing values
Removing duplicate records
Correcting incorrect data
3. Data Transformation
Data is converted into suitable format for analysis.
Example:
Normalization
Encoding categorical data
4. Data Visualization
Visualization helps understand data patterns.
Common charts:
Histogram
Bar chart
Scatter plot
Box plot
EDA Techniques:
Graphical
Non-Graphical
Benefits of EDA 4
Understand dataset structure
Identify patterns and relationships
Detect outliers
Improve model performance
Applications
3
Business analytics
Healthcare prediction
Fraud detection
8. b) Explain Data Mining and Data Warehousing
Data Warehousing 2
A Data Warehouse is a centralized repository used to store large amounts of historical data
from different sources.
Characteristics:
Subject oriented
Integrated
3
Time variant
Non volatile
Data warehouses support decision-making processes.
Example tools:
Oracle
SQL Server
Amazon Redshift
Data Mining
Data mining is the process of discovering patterns and useful information from large datasets. 2
It uses techniques from machine learning and statistics.
Techniques:
Classification
Clustering 3
Association rules
Prediction
Example tools:
Python
RapidMiner
Difference Between Data Mining and Data Warehousing
Data Warehousing
4
Stores large data
Data repository
Used for storage
Data Mining
Analyzes data
Pattern discovery
Used for analysis
Conclusion
Data warehousing stores large volumes of data, while data mining extracts useful patterns
from that data. Both play an important role in data science and business intelligence.
SUBJECT IN CHARGE HOD