Exp 1-14
Exp 1-14
Requirement:-Python 3.13.2
Program Code:-
# Getting current date and time using now().
import datetime
current_time = datetime.datetime.now()
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
# Python program that asks the user to enter their name, and then greet them.
print(f"{message}",name)
Program Output:-
EXPERIMENT-2
Aim:-Write a python program to calculate areas of any geometric figures like circle, rectangle and
triangle.
Requirement:-Python 3.13.2
Program Code:-
# Getting current date and time using now().
# importing datetime module for now()
import datetime
# using now() to get current time
current_time = datetime.datetime.now()
# Printing value of now.
print("Name of student:Shaikh Rafee")
print("Roll no:47 Batch: D3 Branch:AI&DS")
print("Current date and time is:", current_time)
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
import math
choice = int(input(""))
# area of a circle
if choice==1:
area = math.pi*pow(radius,2)
#area of a rectangle
elif choice==2:
width =float(input("Enter the width of the rectangle: "))
area = width*length
#area of a Square
area = side*side
#area of a Parallelogram
area = base*height
else:
Program Output:-
EXPERIMENT-3
Aim:-Write a Python program to calculate the gross salary of an employee. The program should prompt
the user for the basic salary (BS) and then compute the dearness allowance (DA) as 70% of BS, the travel
allowance (TA) as 30% of BS, and the house rent allowance (HRA) as 10% of BS also provident fund (PF)
as 10% of BS. Finally, it should calculate the gross salary as the algebraic sum of BS, DA, TA, HRA and PF
and display the result.
Requirement:-Python 3.13.2
Program Code:-
# Getting current date and time using now().
# importing datetime module for now()
import datetime
# using now() to get current time
current_time = datetime.datetime.now()
# Printing value of now.
print("Name of student:Shaikh Rafee")
print("Roll no:47 Batch: D3 Branch:AI&DS")
print("Current date and time is:", current_time)
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
# Python3 program to calculate the salary
import math
Program Output:-
EXPERIMENT-4
Aim:-Write a Python program to explore basic arithmetic operations. The program should prompt the
user to enter two numbers and then perform addition, subtraction, multiplication, division, and modulus
operations on those numbers. The results of each operation should be displayed to the user.
Requirement:-Python 3.13.2
Program code:-
# Getting current date and time using now().
# importing datetime module for now()
import datetime
# using now() to get current time
current_time = datetime.datetime.now()
# Printing value of now.
print("Name of student:Shaikh Rafee")
print("Roll no:47 Batch: D3 Branch:AI&DS")
print("Current date and time is:", current_time)
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
#Python program to explore basic arithmetic operations.
num1 = int(input(“Enter First number: “))
num2 = int(input(“Enter Second number “))
#basic arithmetic operations
add = num1 + num2
dif = num1 - num2
mul = num1 * num2
div = num1 / num2
floor_div = num1 // num2
power = num1 ** num2
modulus = num1 % num2
print("1.Addition: ")
print('Sum of ', num1, 'and', num2, 'is :', add)
print("2.Substration: ")
print('Difference of ', num1, 'and', num2, 'is :', dif)
print("3.Multiplaction: ")
print('Product of ', num1, 'and', num2, 'is :', mul)
print("4.Division: ")
print('Division of ', num1, 'and', num2, 'is :', div)
print("5.Floor Division: ")
print('Floor Division of ', num1, 'and', num2, 'is :', floor_div)
print("6.Exponent: ")
print('Exponent of ', num1, 'and', num2, 'is :', power)
print("7.Modulus: ")
print('Modulus of ', num1, 'and', num2, 'is :', modulus)
Program Output:-
EXPERIMENT-5
Aim:- Develop a Python program to manage a task list using lists and tuples, including adding, removing,
updating, and sorting tasks.
Requirement:-Python 3.13.2
Program Code:-
# Getting current date and time using now().
# importing datetime module for now()
import datetime
# using now() to get current time
current_time = datetime.datetime.now()
# Printing value of now.
print("Name of student:Shaikh Rafee")
print("Roll no:47 Batch: D3 Branch:AI&DS")
print("Current date and time is:", current_time)
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
#Create a Python List
print(student)
# an empty list
empty_list = []
fruits.append('cherry')
fruits.insert(2, 'cherry')
colors[2] = 'Purple'
# change the third item to 'Blue'
colors[2] = 'Blue'
numbers = [2,4,7,9]
numbers.remove(4)
print(numbers)
del names[1]
print(names)
del names[1: 3]
print(names)
del names
# get a list with items from index 2 to index 4 (index 5 is not included)
# get a list with items from index 2 to index -3 (index -2 is not included)
# get a list with items from index 0 to index 2 (index 3 is not included)
print(numbers)
print(tuple_constructor)
print (names)
print(float_values)
print(mixed_tuple)
print(languages[2]) # C++
cars[0] = 'Nissan'
print(cars)
print(animals)
del animals
#Concatenation of Tuples
x = (1, 2, 3, 4)
y = (5, 6, 7, 8)
z = x + y #tuple concatenation
print(z)
#Slicing of Tuple
print(tu)
Program Output:-
EXPERIMENT-6
Aim:-Create a Python code to demonstrate the use of sets and perform set operations (union,
intersection, difference) to manage student enrollments in multiple courses / appearing for multiple
entrance exams like CET, JEE, NEET etc.
Program Code:-
# Getting current date and time using now().
current_time = datetime.datetime.now()
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
NEET ={2,4,3,7,9,8};
# union
print("Total Number Of Students Registered For CET,JEE & NEET Examination All Together :",Union)
# intersection
print("Common Number Of Students Registered For CET,JEE & NEET Examination :",Intersection)
Intersection1 = CET & JEE
print("Common Number Of Students Registered For CET & JEE Examination :",Intersection1)
print("Common Number Of Students Registered For CET & NEET Examination :",Intersection2)
print("Common Number Of Students Registered For JEE & NEET Examination :",Intersection3)
# difference
# difference
# difference
Difference = NEET-CET-JEE
Program Output:-
EXPERIMENT-7
Aim:-Write a Python program to create, update, and manipulate a dictionary of student
records, including their grades and attendance.
Requirement:-Python 3.13.2
Program Code:-
# Getting current date and time using now().
# importing datetime module for now()
import datetime
# using now() to get current time
current_time = datetime.datetime.now()
# Printing value of now.
print("Name of student:Shaikh Rafee")
print("Roll no:47 Batch: D3 Branch:AI&DS")
print("Current date and time is:", current_time)
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
# Create an empty dictionary
student_dict = {}
# Function to determine grade based on marks
defcalculate_grade(marks):
if marks >= 85:
return 'A'
elif marks >= 70:
return 'B'
elif marks >= 50:
return 'C'
else:
return 'F'
# Get the number of students
n = int(input("Enter the number of students: "))
# Iterate over the range of students to collect information
for i in range(n):
roll_number = input("Enter roll number: ")
name = input("Enter name: ")
marks = float(input("Enter marks: "))
attendance = float(input("Enter attendance: "))
grade = calculate_grade(marks) # Calculate grade based on marks
# Add the student details to the dictionary
student_dict[roll_number] = {'name': name, 'marks': marks, 'attendance': attendance, 'grade':
grade}
# Display the names of students with marks above 75 and attendance above 75
print("\nStudents with marks above 75 and attendance above 75:")
print("-" * 60)
print(f"{'Name':<20} {'Marks':<10} {'Attendance':<10} {'Grade':<10}")
print("-" * 60)
for roll_number, student in student_dict.items():
if student['marks'] > 75 and student['attendance'] > 75:
print(f"{student['name']:<20} {student['marks']:<10} {student['attendance']:<10}
{student['grade']:<10}")
print("-" * 60)
# Updating student details
update_roll = input("\nEnter the roll number of the student to update: ")
if update_roll in student_dict:
# Update student's marks and attendance
new_marks = float(input(f"Enter new marks for {student_dict[update_roll]['name']}: "))
new_attendance = float(input(f"Enter new attendance for {student_dict[update_roll]['name']}:
"))
new_grade = calculate_grade(new_marks) # Recalculate grade based on new marks
# Update the dictionary
student_dict[update_roll]['marks'] = new_marks
student_dict[update_roll]['attendance'] = new_attendance
student_dict[update_roll]['grade'] = new_grade
print(f"\nUpdated details for {student_dict[update_roll]['name']}:")
print(f"Marks: {new_marks}, Attendance: {new_attendance}, Grade: {new_grade}")
else:
print("Student with this roll number does not exist.")
# Display all student records, including the updated ones in a table format
print("\nAll Student Records (Updated):")
print("-" * 70)
print(f"{'Roll Number':<15} {'Name':<20} {'Marks':<10} {'Attendance':<10} {'Grade':<10}")
print("-" * 70)
for roll_number, student in student_dict.items():
print(f"{roll_number:<15} {student['name']:<20} {student['marks']:<10}
{student['attendance']:<10} {student['grade']:<10}")
print("-" * 70)
Program Output:-
EXPERIMENT-8
Aim:-Develop a Python program that takes a numerical input and identifies whether it is even
or odd, utilizing conditional statements and loops.
Requirement:-Python 3.13.2
Program Code:-
# Getting current date and time using now().
# importing datetime module for now()
import datetime
# using now() to get current time
current_time = datetime.datetime.now()
# Printing value of now.
print("Name of student:Shaikh Rafee")
print("Roll no:47 Batch: D3 Branch:AI&DS")
print("Current date and time is:", current_time)
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
# Python program to check if the input number is odd or even.
# A number is even if division by 2 gives a remainder of 0.
# If the remainder is 1, it is an odd number.
for i in range(2): # Loop will run 5 times
# Taking input from the user
number = int(input("Enter a number: "))
# Checking if the number is even or odd
if number % 2 == 0:
print(f"{number} is even.")
else:
print(f"{number} is odd.")
# Ask if the user wants to check another number
cont = input("Do you want to check another number? (yes/no): ")
if cont != 'yes':
print("Goodbye!")
break # Exit the loop if the answer is not "yes"
Program Output:-
EXPERIMENT-9
Aim:-Design a Python program to compute the factorial of a given integer N.
Requirement:-Python 3.13.2
Program Code:-
# Getting current date and time using now().
# importing datetime module for now()
import datetime
# using now() to get current time
current_time = datetime.datetime.now()
# Printing value of now.
print("Name of student:Shaikh Rafee")
print("Roll no:47 Batch: D3 Branch:AI&DS")
print("Current date and time is:", current_time)
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
# Input: An integer number
num =int(input("Enter the number: "))
# Initialize the factorial variable to 1
factorial = 1
# Calculate the factorial using a for loop
for i in range(1, num + 1):
factorial *= i
# Output: The factorial of the number
print(f"The factorial of {num} is {factorial}")
Program Output:-
EXPERIMENT-10
Aim:-Using function, write a Python program to analyze the input number is prime or not.
Requirement:-Python 3.13.2
Program Code:-
# Getting current date and time using now().
# importing datetime module for now()
import datetime
# using now() to get current time
current_time = datetime.datetime.now()
# Printing value of now.
print("Name of student:Shaikh Rafee")
print("Roll no:47 Batch: D3 Branch:AI&DS")
print("Current date and time is:", current_time)
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
def is_prime(number):
# Handle edge case for numbers less than 2
if number < 2:
return False
# Check for factors from 2 to the square root of the number
for i in range(2, int(number ** 0.5) + 1):
if number % i == 0:
return False
return True
# Take input from the user
num = int(input("Enter a number to check if it is prime: "))
# Call the is_prime function and print the result
if is_prime(num):
print(f"{num} is a prime number.")
else:
print(f"{num} is not a prime number.")
Program Output:-
EXPERIMENT-11
Aim:-Implement a simple Python calculator that takes user input and performs basic arithmetic
operations (addition, subtraction, multiplication, division) using functions.
Program Code:-
# Getting current date and time using now().
# importing datetime module for now()
import datetime
# using now() to get current time
current_time = datetime.datetime.now()
# Printing value of now.
print("Name of student:Shaikh Rafee")
print("Roll no:47 Batch: D3 Branch:AI&DS")
print("Current date and time is:", current_time)
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
# Python program for simple calculator
# Function to add two numbers
def add(num1, num2):
return num1 + num2
# Function to subtract two numbers
def subtract(num1, num2):
return num1 - num2
# Function to multiply two numbers
def multiply(num1, num2):
return num1 * num2
# Function to divide two numbers
def divide(num1, num2):
return num1 / num2
print("Please select operation -\n" \
"1. Add\n" \
"2. Subtract\n" \
"3. Multiply\n" \
"4. Divide\n")
n=5
for i in range(n):
# Take input from the user
select = int(input("Select operations form 1, 2, 3, 4 :"))
if select == 1:
number_1 = int(input("Enter first number: "))
number_2 = int(input("Enter second number: "))
print(number_1, "+", number_2, "=",
add(number_1, number_2))
elif select == 2:
number_1 = int(input("Enter first number: "))
number_2 = int(input("Enter second number: "))
print(number_1, "-", number_2, "=",
subtract(number_1, number_2))
elif select == 3:
number_1 = int(input("Enter first number: "))
number_2 = int(input("Enter second number: "))
print(number_1, "*", number_2, "=",
multiply(number_1, number_2))
elif select == 4:
number_1 = int(input("Enter first number: "))
number_2 = int(input("Enter second number: "))
print(number_1, "/", number_2, "=",
divide(number_1, number_2))
else:
print("Invalid input")
print("program Ended")
Program Output:-
EXPERIMENT-12
Aim:-Develop a Python program that reads a text file and prints words of specified lengths (e.g.,
three, four, five, etc.) found within the file.
Requirement:-Python 3.13.2
Program Code:-
# Getting current date and time using now().
# importing datetime module for now()
import datetime
# using now() to get current time
current_time = datetime.datetime.now()
# Printing value of now.
print("Name of student:Shaikh Rafee")
print("Roll no:47 Batch: D3 Branch:AI&DS")
print("Current date and time is:", current_time)
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
# Python program to read
# file word by word
# opening the text file
with open('abcd.txt','r') as file:
# reading each line
for line in file:
#count_word=4
# reading each word
for word in line.split():
#if len(word)==count_word:
# displaying the words
print(word)
Program Output:-
EXPERIMENT-14
Aim:-Write a Python program that takes two numbers as input and performs division.
Implement exception handling to manage division by zero and invalid input errors gracefully.
Requirement:-Python 3.13.2
Program Code:-
# Getting current date and time using now().
# importing datetime module for now()
import datetime
# using now() to get current time
current_time = datetime.datetime.now()
# Printing value of now.
print("Name of student:Shaikh Rafee")
print("Roll no:47 Batch: D3 Branch:AI&DS")
print("Current date and time is:", current_time)
cstr='*'
print(cstr.ljust(70,'*'))
#(Above program code should be included in each program at the start of program code)
# Example of an exception
for i in range(5):
try:
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
result = num1 / num2
print(result)
except ValueError as e:
print("Invalid Input Please Input Integer...")
except ZeroDivisionError as e:
print(e)
Program Output:-