Prac 1 & 2
Prac 1 & 2
LAB MANUAL
Programme (UG/PG): UG
Semester: IV
Objectives:
Outcomes :
Software Requirements: Python 3.6 and more, Notepad ++, Sqlite, Ms access, Ms SQL
List of Experiments
Exp.
Name of Experiment Mapped CO
No
WAP to understand the basics of Python.
i) WAP to check if a Number is Odd or Even.
ii) WAP to develop a simple calculator.
1 iii) WAP to find a given year is a leap or not. 1
iv) WAP to find the factorial of the given number.
v) WAP to evaluate the Fibonacci series for n terms.
vi) WAP to determine whether a given number is Armstrong or not.
Write python programs to understand Advanced data types &
Functions
i) WAP to find circulating „n‟ values using List.
ii) WAP to Check whether an Item Exists in the Python Tuple or not.
iii) WAP to generate and print a dictionary that contains a number
(between 1 and n) in the form (x, x*x)
2 iv) WAP to perform mathematical set operations like union, 1
intersection, subtraction, and symmetric difference.
v) WAP to find the maximum from a list of numbers.
vi) WAP to Perform basic string operations.
vii) WAP to find Sum of N Numbers by importing array modules.
viii) WAP to multiply two matrices.
ix) WAP to swap Two Numbers using functions.
Write python programs to understand concepts of Object Oriented
Programming.
i) WAP to understand Classes, objects, Static method and inner class.
3 1
ii) WAP to understand Constructors.
iii) WAP to understand Inheritance and Polymorphism with Method
overloading and Method Overriding.
Write python programs to understand the concept of modules,
packages and exception handling.
i) WAP to find the distance between two points by importing a math
module.
4 2
ii) WAP to understand Lambda, map, reduce, filter and range
functions.
iii) WAP to understand different types of Exceptions.
iv) WAP to Create and Access a Python Package
Menu driven program for data structure using built in function for link
5 3
list, stack and queue.
Experiment No1
Name of Student
Roll No
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
choice = input("Enter choice (1/2/3/4): ")
if choice in ('1', '2', '3', '4'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
print(f"The result is: {num1 + num2}")
elif choice == '2':
print(f"The result is: {num1 - num2}")
elif choice == '3':
print(f"The result is: {num1 * num2}")
elif choice == '4':
if num2 != 0:
print(f"The result is: {num1 / num2}")
else:
print("Error: Division by zero is not allowed.")
else:
print("Invalid Input")
Source Code:
n=int(input("Enter Number : "))
f=1
for i in range(1, n+1):
f=f*i
print("Factorial of",n,"is",f)
Input and Output:
Source Code:
n=int(input("Enter No. : "))
temp = n
rev=0
while temp!=0:
a=temp%10
rev=rev+ (a*a*a)
temp = int(temp/10)
if(n==rev):
print(n," is an Armstrong Number")
else:
print(n," is not an Armstrong Number")
Input and Output:
Experiment No.2
Name of Student
Roll No
Aim: Write python programs to understand Advanced data types & Functions
Objectives:
To study the basics of python programming.
Outcome: Students will be able to implement the basics of pythonprogramming.
n = len(lst)
Output:
ii) WAP to Check whether an Item Exists in the Python Tuple or not.
Code:
my_tuple = (10, 20, 30, 40, 50)
if item in my_tuple:
print(f"{item} exists in the tuple.")
else:
Output:
iii) WAP to generate and print a dictionary that contains a number (between 1 and n) in the
form (x, x*x)
Code:
n = int(input("Enter a number n: "))
my_dict = {}
Output:
iv) WAP to perform mathematical set operations like union, intersection, subtraction, and
symmetric difference.
Code:
set1 = {1, 2, 3, 4, 5}
set2 = {4, 5, 6, 7, 8}
print("Union:", union_result)
print("Intersection:", intersection_result)
print("Subtraction:", subtraction_result)
print("Symmetric Difference:", symmetric_difference_result)
Output:
Output:
str1 = "Hello"
str2 = "World"
print("Concatenation:", concatenation)
print("Repetition:", repetition)
print("Length of str1:", length_str1)
print("Length of str2:", length_str2)
Output:
for i in range(n):
num = int(input(f"Enter element {i+1}: "))
arr.append(num)
sum_of_numbers = sum(arr)
print("Sum of numbers:", sum_of_numbers)
Output:
Output:
print("After swapping:")
LAB MANUAL [IV --- Python Lab] Page 14
Mahatma Gandhi Mission's College of Engineering and Technology
print("a =", a)
print("b =", b)
Output: