Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 1
AIM
Basic data types and operators: Create a program that prompts the user for their name and age
and prints a personalized message.
THEORY
Name·Navyaa Sambhar Enrollment No.· 36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
# Program to take user's name and age and display a personalized message
# Taking input from user
name = input("Enter your name: ")
age = int(input("Enter your age: "))
# Displaying personalized message
print("Hello", name + "!")
print("You are", age, "years old.")
print("Welcome to Python programming!")
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand basic data types in Python (int, string)
2. Learn how to take user input
3. Perform type conversion using int()
4. Use print statements to display output
5. Understand string concatenation
VIVA QUESTIONS
Q1. What are basic data types in Python?
Answer: Basic data types include int, float, string (str), and boolean (bool).
Q2. What does the input() function do?
Answer: It takes input from the user as a string.
Q3. Why do we use int() in this program?
Answer: To convert the input age from string to integer.
Q4. What is string concatenation?
Answer: Combining two or more strings using operators like +.
Q5. What will happen if we don't convert age using int()?
Answer: Age will be treated as a string, and numeric operations cannot be performed properly.
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 2
AIM
Conditional statements: Create a program that prompts the user for their age and tells them if
they can vote in the next election.
THEORY
Name—Navyaa Sambhar Enrollment No.—36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand the concept of conditional statements
2. Learn how to use if-else decision making
3. Apply comparison operators (>=)
4. Develop logic for real-life scenarios
5. Improve problem-solving skills
VIVA QUESTIONS
Q1. What is a conditional statement?
Answer: It is used to execute a block of code based on a condition.
Q2. What is the syntax of an if-else statement?
Answer:
if condition:
# code
else:
# code
Q3. What operator is used to check voting
eligibility? Answer: Greater than or equal to (>=)
Q4. What is the minimum voting age in India?
Answer: 18 years.
Q5. What happens if the condition in if is False?
Answer: The code inside the else block is executed.
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 3
AIM
Loops: Create a program that calculates the factorial of a number entered by the user using a
loop.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
# Program to calculate factorial using loop
# Taking input from user
num = int(input("Enter a number: "))
# Initializing factorial
factorial = 1
# Checking if number is negative
if num < 0:
print("Factorial is not defined for negative numbers.")
else:
# Loop to calculate factorial
for i in range(1, num + 1):
factorial *= i
print("Factorial of", num, "is", factorial)
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand the concept of loops (for loop)
2. Learn how to perform repetitive calculations
3. Understand factorial logic
4. Handle conditional cases (negative numbers)
5. Improve logical thinking and programming skills
VIVA QUESTIONS
Q1. What is a loop in Python?
Answer: A loop is used to execute a block of code multiple times.
Q2. What is a factorial?
Answer: It is the product of all positive integers up to a given number.
Q3. Which loop is used in this program?
Answer: for loop.
Q4. What is the factorial of 0?
Answer: 1.
Q5. Why do we check for negative numbers?
Answer: Because factorial is not defined for negative numbers.
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 4
AIM
Lists and arrays: Create a program that prompts the user for a list of numbers and then sorts
them in ascending order.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
# Program to sort a list of numbers in ascending order
# Taking input from user
numbers = input("Enter numbers separated by space: ")
# Converting input string into list of integers
num_list = list(map(int, [Link]()))
# Sorting the list
num_list.sort()
# Displaying sorted list
print("Sorted list in ascending order:", num_list) print("Factorial of", num, "is", factorial)
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand the concept of lists in Python
2. Learn how to take multiple inputs from user
3. Use split() function for input processing
4. Apply type casting with map()
5. Perform sorting using sort() method
VIVA QUESTIONS
Q1. What is a list in Python?
Answer: A list is a collection of elements stored in a single variable.
Q2. What does the split() function do?
Answer: It splits a string into a list based on spaces or a specified separator.
Q3. What is the use of map() function?
Answer: It applies a function to all elements of an iterable (e.g., converting strings to
integers).
Q4. What does the sort() method do?
Answer: It sorts the list in ascending order.
Q5. Are lists mutable in Python?
Answer: Yes, lists are mutable and can be modified after creation.
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 5
AIM
Strings and string manipulation: Create a program that prompts the user for a string and then
prints out the string reversed.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
# Program to reverse a string
# Taking input from user
text = input("Enter a string: ")
# Reversing the string using slicing
reversed_text = text[::-1]
# Displaying result
print("Reversed string:", reversed_text)
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand the concept of strings in Python
2. Learn string slicing technique
3. Perform string manipulation operations
4. Improve understanding of indexing
5. Write efficient code for reversing data
VIVA QUESTIONS
Q1. What is a string in Python?
Answer: A string is a sequence of characters enclosed in quotes.
Q2. What does [::-1] mean?
Answer: It reverses the string using slicing (start:end:step = -1).
Q3. Are strings mutable in Python?
Answer: No, strings are immutable.
Q4. What is string slicing?
Answer: It is a method to extract a part of a string using index positions.
Q5. Can we reverse a string without slicing?
Answer: Yes, using loops or functions like reversed().
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 6
AIM
Functions: Create a program that defines a function to calculate the area of a circle based on
the radius entered by the user.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
# Program to calculate area of a circle using function
import math
# Defining function
def calculate_area(radius):
return [Link] * radius * radius
# Taking input from user
r = float(input("Enter the radius of the circle: "))
# Calling function
area = calculate_area(r)
# Displaying result
print("Area of the circle is:", area)
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand the concept of functions
2. Learn how to define and call functions
3. Use parameters and return values
4. Apply mathematical formulas in Python
5. Improve modular programming skills
VIVA QUESTIONS
Q1. What is a function in Python?
Answer: A function is a block of code that performs a specific task and can be reused.
Q2. What keyword is used to define a function?
Answer: def
Q3. What is the formula for area of a circle?
Answer: πr²
Q4. Why do we use [Link]?
Answer: It provides a precise value of π (pi).
Q5. What is the benefit of using functions?
Answer: It reduces code duplication and improves readability.
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 7
AIM
Classes and objects: Create a program that defines a class to represent a car and then creates
an object of that class with specific attributes. Functions: Create a program that defines a
function to calculate the area of a circle based on the radius entered by the user.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
# Program to demonstrate class and object
# Defining a class
class Car:
# Constructor
def __init__(self, brand, model, year):
[Link] = brand
[Link] = model
[Link] = year
# Method to display details
def display_details(self):
print("Car Brand:", [Link])
print("Car Model:", [Link])
print("Manufacturing Year:", [Link])
# Creating an object
car1 = Car("Mahindra", "Scorpio N", 2023)
# Calling method
car1.display_details()
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand the concept of classes and objects
2. Learn how to define a constructor (__init__)
3. Work with attributes and methods
4. Understand object creation
5. Apply basic principles of OOP
VIVA QUESTIONS
Q1. What is a class in Python?
Answer: A class is a blueprint for creating objects.
Q2. What is an object?
Answer: An object is an instance of a class.
Q3. What is the purpose of __init__() method?
Answer: It is a constructor used to initialize object attributes.
Q4. What is self in Python?
Answer: It refers to the current instance of the class.
Q5. Can a class have multiple objects?
Answer: Yes, a class can have multiple objects with different values.
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 9
AIM
Regular expressions: Create a program that uses regular expressions to find all instances of a
specific pattern in a text file.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
[Link]
[Link]
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
# Program to find pattern using regular expressions
import re
# Open file in read mode
with open("[Link]", "r") as file:
data = [Link]()
# Define pattern (example: find all words starting with 'H')
pattern = r'\bH\w+'
# Find all matches
matches = [Link](pattern, data)
# Display matches
print("Matches found:", matches)
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand regular expressions
2. Learn pattern matching techniques
3. Use re module in Python
4. Extract specific data from text
5. Work with file handling + RegEx
VIVA QUESTIONS
Q1. What is a regular expression?
Answer: A pattern used to match strings.
Q2. Which module is used for RegEx in Python?
Answer: re module
Q3. What does [Link]() do?
Answer: It returns all matches of a pattern.
Q4. What does \b represent in RegEx?
Answer: Word boundary
Q5. Can RegEx be used for email validation?
Answer: Yes
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 10
AIM
Exception handling: Create a program that prompts the user for two numbers and then divides
them, handling any exceptions that may arise.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
# Program to demonstrate exception handling in division
try:
# Taking input from user
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
# Performing division
result = num1 / num2
except ZeroDivisionError:
print("Error: Cannot divide by zero.")
except ValueError:
print("Error: Invalid input. Please enter numeric values.")
else:
print("Result:", result)
finally:
print("Program executed successfully.")
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand exception handling concepts
2. Learn to use try-except blocks
3. Handle runtime errors effectively
4. Prevent program crashes
5. Improve robustness of code
VIVA QUESTIONS
Q1. What is an exception?
Answer: An error that occurs during program execution.
Q2. What is the purpose of try block?
Answer: It contains code that may cause an exception.
Q3. What does except block do?
Answer: It handles the exception.
Q4. What is ZeroDivisionError?
Answer: It occurs when dividing by zero.
Q5. What is the use of finally block?
Answer: It executes regardless of whether an exception occurs or not.
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 11
AIM
GUI programming: Create a program that uses a graphical user interface (GUI) to allow the
user to perform simple calculations.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
import tkinter as tk
# Function to perform addition
def add():
result = float([Link]()) + float([Link]())
label_result.config(text="Result: " + str(result))
# Creating window
root = [Link]()
[Link]("Simple Calculator")
# Input fields
entry1 = [Link](root)
[Link]()
entry2 = [Link](root)
[Link]()
# Button
btn_add = [Link](root, text="Add", command=add)
btn_add.pack()
# Result label
label_result = [Link](root, text="Result: ")
label_result.pack()
# Run GUI
[Link]()
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand basics of GUI programming
2. Learn to use Tkinter library
3. Create windows, buttons, and input fields
4. Handle user input through GUI
5. Build interactive applications
VIVA QUESTIONS
Q1. What is GUI?
Answer: Graphical User Interface for user interaction.
Q2. Which library is used here?
Answer: Tkinter
Q3. What is mainloop()?
Answer: It runs the GUI application.
Q4. What is a widget?
Answer: GUI element like button, label, entry.
Q5. Can Tkinter handle events?
Answer: Yes, using functions and commands.
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 12
AIM
Web scraping: Create a program that uses a web scraping library to extract data from a
website and then stores it in a database.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
import requests
from bs4 import BeautifulSoup
import sqlite3
# Step 1: Fetch MAIT website
url = "[Link]
response = [Link](url)
# Step 2: Parse HTML
soup = BeautifulSoup([Link], "[Link]")
# Extract all links text (more reliable for this site)
data_list = [[Link]() for link in soup.find_all("a") if [Link]() != ""]
# Step 3: Create database
conn = [Link]("mait_data.db")
cursor = [Link]()
[Link]("CREATE TABLE IF NOT EXISTS data (title TEXT)")
# Step 4: Insert data into database
for item in data_list:
[Link]("INSERT INTO data (title) VALUES (?)", (item,))
[Link]()
# Step 5: Display stored data
[Link]("SELECT * FROM data")
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
rows = [Link]()
print("Scraped Data:")
for row in rows[:10]: # print first 10 items
print(row[0])
[Link]()
print("\nData scraped and stored successfully.")
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand concept of web scraping
2. Learn to use requests and BeautifulSoup
3. Extract data from HTML
4. Store data into SQLite database
5. Integrate multiple technologies (web + database)
VIVA QUESTIONS
Q1. What is web scraping?
Answer: Extracting data from websites automatically.
Q2. Which library is used to fetch web pages?
Answer: requests
Q3. What is BeautifulSoup used for?
Answer: Parsing HTML and extracting data.
Q4. What is SQLite?
Answer: A lightweight database built into Python.
Q5. Is web scraping legal?
Answer: It depends on the website’s terms and conditions.
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 13
AIM
Data visualization: Create a program that reads data from a file and then creates a
visualization of that data using a data visualization library.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
# Data visualization using matplotlib
import [Link] as plt
# Read data from file
with open("[Link]", "r") as file:
data = [Link]()
# Convert data to integers
values = [int([Link]()) for x in data]
# Create x-axis (index values)
x = list(range(1, len(values) + 1))
# Plot graph
[Link](x, values)
# Labels and title
[Link]("Index")
[Link]("Values")
[Link]("Data Visualization")
# Show graph
[Link]()
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand data visualization concepts
2. Learn to use Matplotlib library
3. Read data from files
4. Plot graphs using Python
5. Analyze data visually
VIVA QUESTIONS
Q1. What is data visualization?
Answer: Representing data graphically.
Q2. Which library is used here?
Answer: Matplotlib
Q3. What does [Link]() do?
Answer: It creates a line graph.
Q4. What is the purpose of [Link]()?
Answer: It displays the graph.
Q5. Why is visualization important?
Answer: It helps in understanding data easily.
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 14
AIM
Machine learning: Create a program that uses a machine learning library to classify images
based on their content.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
from [Link].mobilenet_v2 import MobileNetV2, preprocess_input,
decode_predictions
from [Link] import image
import numpy as np
# Load pre-trained model
model = MobileNetV2(weights='imagenet')
# Load image (give path of your image)
img_path = "[Link]"
img = image.load_img(img_path, target_size=(224, 224))
# Convert image to array
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
# Preprocess image
img_array = preprocess_input(img_array)
# Predict
predictions = [Link](img_array)
# Decode results
decoded = decode_predictions(predictions, top=3)[0]
print("Predictions:")
for i in decoded:
print(i[1], ":", i[2])
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand basics of machine learning
2. Learn image classification concept
3. Use pre-trained models
4. Work with TensorFlow/Keras
5. Perform prediction on real images
VIVA QUESTIONS
Q1. What is machine learning?
Answer: A method where machines learn from data and make predictions.
Q2. What is image classification?
Answer: Identifying the category of an image.
Q3. Which model is used here?
Answer: MobileNetV2
Q4. What is a pre-trained model?
Answer: A model already trained on large datasets.
Q5. Why use pre-trained models?
Answer: Saves time and gives accurate results without training from scratch.
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
PROGRAM 15
AIM
Networking: Create a program that uses a networking library to communicate with a server
and retrieve data from it.
THEORY
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
SOURCE CODE
# Networking program to fetch data from a server
import requests
# URL of server (API)
url = "[Link]
# Send request to server
response = [Link](url)
# Display status code
print("Status Code:", response.status_code)
# Display data received from server
print("Data received:\n", [Link])
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6
Maharaja Agrasen Institute Of Technology Department of Information Technology
LEARNING OUTCOMES
1. Understand basics of networking in Python
2. Learn client-server communication
3. Use requests library
4. Fetch data from APIs
5. Handle HTTP responses
VIVA QUESTIONS
Q1. What is networking?
Answer: Communication between systems over a network.
Q2. Which library is used here?
Answer: requests
Q3. What is an API?
Answer: Interface to communicate with a server.
Q4. What does status code 200 mean?
Answer: Successful request.
Q5. What method is used to fetch data?
Answer: GET request.
Name·Navyaa Sambhar Enrollment No.·36814803123 Semester-- 6