Python Simple Program Lab Work For B.SC IT Students
Python Simple Program Lab Work For B.SC IT Students
No: 01
Date: 15.12.2023
PERSONAL DETAILS
PROGRAM:
name=input("Enter Your Name: ")
add=input("Enter Your Full Address: ")
print("\n\tPersonal Details")
print("Name :",name)
print("Address :",add)
print("Phone Number :",ph)
print("College Name :",clg)
print("Course :",co)
print("Subject :",sub)
OUTPUT:
PROGRAM:
a=int(input("Enter first integer: "))
b=int(input("Enter second integer: "))
OUTPUT:
Enter first integer: 52
Enter second integer: 95
Enter third integer: 12
PROGRAM:
m1r=int(input("Enter the number of rows for first matrix:"))
m1c=int(input("Enter the number of columns for first matrix:"))
if(m1c==m2r):
print("Enter the entries row wise for first matrix:")
for i in matrix1:
print(i)
print("Enter the entries row wise for second matrix:")
for j in matrix2:
print(j)
print("\nProduct: ")
result=[[sum(a*b for a,b in zip(matrix1_row,matrix2_col)) for matrix2_col in zip(*matrix2)]
for matrix1_row in matrix1]
for k in result:
print(k)
else:
print("\nError:Enter the number of columns for first matrix is same as number of rows for
second matrix")
OUTPUT:
Enter the number of rows for first matrix:2
>>>
Enter the number of rows for first matrix:2
2
2
2
2
The first matrix is:
[2, 2]
[2, 2]
2
2
2
The second matrix is:
[2, 2]
[2, 2]
Product:
[8, 8]
[8, 8]
Ex.No: 04.a
Date: 08.01.2024
PROGRAM:
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b,a%b)
a=int(input("Enter a first number for GCD: "))
OUTPUT:
Enter a first number for GCD: 34
PROGRAM:
def fact(n):
if(n==1 or n==0):
return 1
else:
return n*fact(n-1)
n=int(input("Enter a number for Factorial: "))
if(n>=0):
res=fact(n)
OUTPUT:
Enter a number for Factorial: 5
PROGRAM:
print("\t\t\t\tSorting String")
s=str(input("Enter a string : "))
print("\n\t\t\t\tSorting List")
l=list(input("Enter a List : ").split())
print("\n\t\t\t\tSorting Tuple")
Sorting List
Sorting Tuple
Enter a Tuple : mala divya swetha sujitha priya
SIMPLE CALCULATOR
PROGRAM:
import tkinter as tk
def btn_click(val):
current_text = entry.get()
entry.delete(0, tk.END)
entry.delete(0, tk.END)
def calculate():
try:
result = eval(entry.get())
entry.delete(0, tk.END)
entry.insert(tk.END, str(result))
except:
entry.delete(0, tk.END)
entry.insert(tk.END, "Error")
win = tk.Tk()
win.title("Calculator")
win.mainloop()
OUTPUT:
Ex.No: 07
Date: 01.02.2024
SUM OF ARRAY
PROGRAM:
array=[int(x) for x in input("Enter a array: ").split()]
print("The sum of array ",array," is: ",sum(array))
OUTPUT:
Enter a array: 56 23 87 -83 67
The sum of array [56, 23, 87, -83, 67] is: 150
INHERITANCE
PROGRAM:
class Class1: obj.fun2()
def fun1(self): def multiple():
elif i==4:
print("\t\t\t\tInheritance") hierarchical()
Inheritance
1. Simple Inheritance
3. Multilevel Inheritance
4. Hierarchical Inheritance 1. Simple Inheritance
Course : BCA
Ex.No: 09
Date: 15.02.2024
SLICE A LIST
PROGRAM:
a = list(input("Enter a list: ").split())
print("Original List:", a)
while True:
print("\nChoose a slicing method:")
elif i == 2:
start = int(input("Enter the start index: "))
print("Exiting program.")
break
else:
Enter a list: sophi inba nithi jeba hari nithi Choose a slicing method:
divya
1. Start and End index
Original List: ['sophi', 'inba', 'nithi', 'jeba',
'hari', 'nithi', 'divya'] 2. Start, End, and Step
3. Reverse the list
2. Start, End, and Step Reversed List: ['divya', 'nithi', 'hari', 'jeba',
'nithi', 'inba', 'sophi']
3. Reverse the list
4. Exit
Choose a slicing method:
Enter your choice: 1
1. Start and End index
Enter the start index: 1
2. Start, End, and Step
Enter the end index: 5
3. Reverse the list
Sliced List: ['inba', 'nithi', 'jeba', 'hari']
4. Exit
PROGRAM:
txt=input("Enter a sentence: ").split()
print("The no.of words in the sentence is: ",len(txt))
OUTPUT:
Enter a sentence: Hello, we are studying B.Sc (IT) in Sri Sankara Bhagavathi Arts And Science
College at Kommadikottai
COPY A FILE
PROGRAM:
import shutil
source_file = input("Enter the path of the source file: ")
shutil.copyfile(source_file, destination_file)
print("File copied successfully.")
except FileNotFoundError:
print("File not found.")
except Exception as e:
print("An error occurred:", str(e))
OUTPUT:
PROGRAM:
def valid(password):
return (
while True:
if valid(password1):
if valid(password2):
if(password1==password2):
print("Password is valid.")
break
else:
else:
else:
Password is valid.