Python Manual For M.SC CS
Python Manual For M.SC CS
Aim:
To write a python program to calculate the arithmetic operations.
Code:
con = 'y'
while con=='y':
print('\nArithmetic Operations')
print('---------------------\n')
print('1.Addition')
print('2.Subrtraction')
print('3.Multiplication')
print('4.division\n')
co=int(input())
match co:
case 1:
case 2:
case 3:
case 4:
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 2 PRIME / PERFECT NUMBER CHECKING
Aim:
Code:
con = 'y'
while con=='y':
print('----------------------------------\n')
print("1.Prime no Checking")
print("2.Perfect no Checking")
co=int(input())
match co:
case 1:
flag=0
for i in range(2,(a//2)+1):
if(a%i==0):
flag=1
break
if(flag==1):
else:
print(a,"is Prime")
case 2:
b=0
for i in range(1,a):
if(a%i==0):
b=b+i
if(b==a):
print(a,"is perfect")
else:
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 3 ADAM / ARMSTRONG NUMBER CHECKING
Aim:
To Write a python program to find the Adam Number and Armstrong Number.
Code :
con = 'y'
while con=='y':
print('-----------------------------------\n')
print("1.Adam no Checking")
print("2.Armstrong no Checking")
co=int(input())
match co:
case 1:
def reverseDigits(num) :
rev = 0
num //= 10
return rev
def square(num) :
def checkAdamNumber(num) :
a = square(num)
b = square(reverseDigits(num))
return a==reverseDigits(b)
if checkAdamNumber(num):
else:
case 2:
sum = 0
temp = num
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
else:
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 4 TO CREATE AN ALARM
Aim:
To Write a python program to create an Alarm.
Code:
import datetime
import winsound
print('\nCREATE an ALARM')
print('-----------------\n')
def set_alarm(alarm_time):
while True:
current_time = datetime.datetime.now()
print("Wake Up!")
break
def main():
alarm_time = datetime.datetime.now()
second=0)
set_alarm(alarm_time)
if __name__ == "__main__":
main()
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 5 PAINT PROGRAM (ROSETTE) USING TURTLE
Aim:
Code:
import turtle
print('-------------------------------------\n')
angleInc = 360/total
width( breadth )
color( col )
for i in range(total):
forward( length )
left( angleInc )
left( angleInc )
rosette(10,40,1,"blue",36)
rosette(5,80,1,"red",36)
turtle.exitonclick()
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 6 LIST OPERATIONS
Aim:
To Write a python program and check the following operations in List.
i) Insert
ii) Delete
iii) Sort
iv) Reversed
v) Slice a list
vi) Sum and Average
Code:
print('\nLIST OPERATIONS')
print('-----------------\n')
my_list=[]
print("""1.Insert 2.Remove 3.Sort the list 4.Reverse the list \n5.Slice a List
6.Sum 7. Average""")
con='y'
while con=='y':
match choice:
case 1:
my_list.append(item)
case 2:
my_list.remove(item)
print("Removed list : ",my_list)
case 3:
my_list.sort()
case 4:
my_list.reverse()
case 5:
sliced_list = my_list[start:end]
case 6:
total_sum=sum(my_list)
case 7:
avg=sum(my_list)/len(my_list)
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 7 TUPLE OPERATIONS
Aim:
To Write a python program and check the following operations in Tuples.
i) Concatenation
ii) Slice a Tuple
iii) Count
iv) Search
v) Maximum and Minimum
Code:
print('\nTUPLE OPERATIONS')
print('------------------\n')
my_tuple1=(1,2,3,5,2,6,3,5)
my_tuple2=("Hello","World")
print(my_tuple1)
print(my_tuple2)
con='y'
while con=='y':
match choice:
case 1:
concatenated_tuple=my_tuple1+my_tuple2
case 2:
sliced_tuple=my_tuple1[start:end]
print(sliced_tuple)
case 3:
count_of_5=my_tuple1.count(numm)
print("\nCount of",numm,"is",count_of_5)
case 4:
if search_item in my_tuple1:
print(search_item,"is found")
else:
case 5:
max_val=max(my_tuple1)
min_val=min(my_tuple1)
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 8 DICTIONARIES
Aim:
To Write a python program and check the following operations in Dictionaries.
i) Insert
ii) Delete / Remove
iii) Search
iv) Display Keys
v) Display Values
Code:
print('\nDICTIONARY OPERATIONS')
print('-----------------------\n')
dict={}
con='y'
while con=='y':
match choice:
case 1:
dict[key] = value
print(dict)
case 2:
if key in dict:
del dict[key]
print("Key removed",dict)
else:
value = dict.get(key)
if value:
print(f"{key}: {value}")
else:
case 4:
print("Keys:", list(dict.keys()))
case 5:
print("value", list(dict.values()))
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 9 SET
Aim:
To Write a python program and check the following operations in Set.
i) Union
ii) Intersection
iii) Difference
iv) Equal or Not Equal
Code:
A={1,2,6,8,9}
B={0,5,7,2,6}
print(A)
print(B)
print("""1)Union
2) Intersection
3) Difference
con='y'
while con=='y':
match choice:
case 1:
case 2:
case 3:
case 4:
if(A==B):
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 10 EXCEPTION HANDLING
Aim:
To write a python program for Exception handling.
Code:
print('\nEXCEPTION HANDLING')
print('--------------------\n')
def get_numeric_input(prompt):
while True:
try:
value = float(input(prompt))
return value
except ValueError:
result = n1 * n2
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 11 DISPLAY STUDENT DETAILS
Aim:
To write a python program to display student details.
Code:
print('\nDISPLAY STUDENT DETAILS')
print('-------------------------\n')
class Student:
def getStudentDetails(self):
self.rollno = input("Enter Roll Number : ")
self.name = input("Enter Name : ")
self.cpp = int(input("Enter cpp Marks : "))
self.java = int(input("Enter Java Marks : "))
self.css = int(input("Enter Python Marks : "))
def total(self):
self.total_marks = self.cpp + self.java + self.css
def avg(self):
self.average_marks = (self.cpp + self.java + self.css) / 300 * 100
def grade(self):
if self.average_marks>= 90:
return "A"
elifself.average_marks>= 80:
return "B"
elifself.average_marks>= 70:
return "C"
elifself.average_marks>= 60:
return "D"
else:
return "F"
def display_details(self):
print("Student Details:")
print("Roll Number:", self.rollno)
print("Name:", self.name)
print("Total Marks:", self.total_marks)
print("Average Marks:", self.average_marks)
print("Grade:", self.grade())
S1 = Student()
S1.getStudentDetails()
S1.total()
S1.avg()
S1.display_details()
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 12 EMPLOYEE DATA’S STORED
Aim:
To write a python program to employee data’s stored.
Code:
print('--------------------------\n')
class Employee:
def __init__(self):
overtime = 0
overtime = hours_worked - 50
def print_employee_details(self):
# Driver Code
employees = []
for i in range(n):
emp = Employee()
emp.calculate_salary(hours_worked)
employees.append(emp)
print("\nEmployee Details:")
emp.print_employee_details()
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 13 RESTAURANT MANAGEMENT
Aim:
To write a python program for Restaurant Management.
Code:
class Restaurant:
def __init__(self):
self.menu_items = {
"Cheeseburger": 9.99,
self.book_table = []
self.customer_orders = []
self.book_table.append(table_number)
else:
self.customer_orders.append(order_details)
else:
def print_menu_items(self):
print("\nMenu:")
print(f"{item}: ${price:.2f}")
def print_table_reservations(self):
print("\nTables reserved:")
print(f"Table {table}")
def print_customer_orders(self):
print("\nCustomer orders:")
# Driver code
restaurant = Restaurant()
restaurant.print_menu_items()
for _ in range(c):
restaurant.book_table(table_number)
restaurant.customer_order(table_number, order)
# Display results
restaurant.print_menu_items()
restaurant.print_table_reservations()
restaurant.print_customer_orders()
Result:
Thus the program was successfully executed and the output was verified.
Output:
Menu:
Cheeseburger: $9.99
Menu:
Cheeseburger: $9.99
Tables reserved:
Table 1
Table 2
Customer orders:
Table 1: Cheeseburger
Aim:
Code:
class Person:
self.name = name
self.age = age
def display_details(self):
class Employee(Person):
super().__init__(name, age)
self.emp_id = empid
self.dept = dept
def display_empdetails(self):
self.display_details()
# Driver Code
print("\nEmployee Details:")
emp.display_empdetails()
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 15 MULTIPLE INHERITANCE
Aim:
Code:
class Person:
self.name = name
self.age = age
def display_personal_details(self):
class Department:
self.emp_id = empid
self.dept = dept
def display_dept_details(self):
def display_emp_details(self):
self.display_personal_details()
self.display_dept_details()
# Driver Code
print("\nEmployee Details:")
emp.display_emp_details()
Result:
Thus the program was successfully executed and the output was verified.
Output:
Ex.No: 16 File Operations
Aim:
Code:
file.close()
content = file.read()
file.close()
file.close()
content = file.read()
file.close()
Result:
Thus the program was successfully executed and the output was verified.
Output: