0% found this document useful (0 votes)
16 views

Python Simple Program Lab Work For B.SC IT Students

python simple program lab work for B.Sc IT students prepared by sri sankara bhagavathi art and science IT students

Uploaded by

tstharshu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Python Simple Program Lab Work For B.SC IT Students

python simple program lab work for B.Sc IT students prepared by sri sankara bhagavathi art and science IT students

Uploaded by

tstharshu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Ex.

No: 01
Date: 15.12.2023

PERSONAL DETAILS

PROGRAM:
name=input("Enter Your Name: ")
add=input("Enter Your Full Address: ")

ph=int(input("Enter Your Phone Number: "))


clg=input("Enter Your College Name: ")

co=input("Enter Your Course: ")


sub=input("Enter Your Subject: ")

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:

Enter Your Name: Tharshini Personal Details

Enter Your Full Address: 163,Puliyadi Name : Tharshini


Street
Address : 163,Puliyadi Street
Enter Your Phone Number: 8300742356
Phone Number : 8300742356
Enter Your College Name: SSB College
College Name : SSB College
Enter Your Course: B.Sc(IT)
Course : B.Sc(IT)
Enter Your Subject: Python
Subject : Python
Ex.No: 02
Date: 28.12.2023

LARGEST OF THREE INTEGERS

PROGRAM:
a=int(input("Enter first integer: "))
b=int(input("Enter second integer: "))

c=int(input("Enter third integer: "))


max=(a if(a>b and a>c)else b if(b>a)else c)

print(max," is the gratest number")

OUTPUT:
Enter first integer: 52
Enter second integer: 95
Enter third integer: 12

95 is the gratest number


Ex.No: 03
Date: 04.01.2024

PRODUCT OF TWO MATRIX

PROGRAM:
m1r=int(input("Enter the number of rows for first matrix:"))
m1c=int(input("Enter the number of columns for first matrix:"))

m2r=int(input("Enter the number of rows for second matrix:"))


m2c=int(input("Enter the number of columns for second matrix:"))

if(m1c==m2r):
print("Enter the entries row wise for first matrix:")

matrix1=[[int(input()) for c in range (m1c)] for r in range(m1r)]


print("The first matrix is:")

for i in matrix1:
print(i)
print("Enter the entries row wise for second matrix:")

matrix2=[[int(input()) for c in range (m2c)] for r in range(m2r)]


print("The second matrix is:")

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 columns for first matrix:3


Enter the number of rows for second matrix:2

Enter the number of columns for second matrix:2


Error: Enter the number of columns for first matrix is same as number of rows for second matrix

>>>
Enter the number of rows for first matrix:2

Enter the number of columns for first matrix:2


Enter the number of rows for second matrix:2

Enter the number of columns for second matrix:2


Enter the entries row wise for first matrix:

2
2
2

2
The first matrix is:

[2, 2]
[2, 2]

Enter the entries row wise for second matrix:


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

GCD USING RECURSIVE FUNCTION

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: "))

b=int(input("Enter a second number for GCD: "))


result=gcd(a,b)

print("GCD of given number is: ",result)

OUTPUT:
Enter a first number for GCD: 34

Enter a second number for GCD: 87


GCD of given number is: 1

Enter a first number for GCD: 10

Enter a second number for GCD: 70


GCD of given number is: 10
Ex.No: 04.b
Date: 08.01.2024

FACTORIAL USING RECURSIVE FUNCTION

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)

print("Factorial of a number ",n," is ",res)


else:
print("Error: Enter a positive number")

OUTPUT:
Enter a number for Factorial: 5

Factorial of a number 5 is 120

Enter a number for Factorial: -7


Error: Enter a positive number
Ex.No: 05
Date: 22.01.2024

SORTING A STRING, LIST, TUPLE

PROGRAM:
print("\t\t\t\tSorting String")
s=str(input("Enter a string : "))

print("Type of input : ",type(s))


print("Ascending Order : ",sorted(s))

print("Descending Order : ",sorted(s,reverse=True))

print("\n\t\t\t\tSorting List")
l=list(input("Enter a List : ").split())

print("Type of input : ",type(l))


print("Ascending Order : ",list(sorted(l)))
print("Descending Order : ",list(sorted(l,reverse=True)))

print("\n\t\t\t\tSorting Tuple")

t=tuple(input("Enter a Tuple : ").split())


print("Type of input : ",type(t))

print("Ascending Order : ",tuple(sorted(t)))


print("Descending Order : ",tuple(sorted(t,reverse=True)))
OUTPUT:
Sorting String

Enter a string : Thars


Type of input : <class 'str'>

Ascending Order : ['T', 'a', 'h', 'r', 's']


Descending Order : ['s', 'r', 'h', 'a', 'T']

Sorting List

Enter a List : inba sophi hari thars nithi rithi jeba


Type of input : <class 'list'>

Ascending Order : ['hari', 'inba', 'jeba', 'nithi', 'rithi', 'sophi', 'thars']


Descending Order : ['thars', 'sophi', 'rithi', 'nithi', 'jeba', 'inba', 'hari']

Sorting Tuple
Enter a Tuple : mala divya swetha sujitha priya

Type of input : <class 'tuple'>


Ascending Order : ('divya', 'mala', 'priya', 'sujitha', 'swetha')

Descending Order : ('swetha', 'sujitha', 'priya', 'mala', 'divya')


Ex.No: 06
Date: 30.01.2024

SIMPLE CALCULATOR

PROGRAM:
import tkinter as tk
def btn_click(val):

current_text = entry.get()
entry.delete(0, tk.END)

entry.insert(tk.END, current_text + str(val))


def clear():

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")

entry = tk.Entry(win, width=20, font=('Arial', 14), justify='right')


entry.grid(row=0, column=0, columnspan=4)

buttons = [('7', 1, 0), ('8', 1, 1), ('9', 1, 2), ('/', 1, 3),


('4', 2, 0), ('5', 2, 1), ('6', 2, 2), ('*', 2, 3),

('1', 3, 0), ('2', 3, 1), ('3', 3, 2), ('-', 3, 3),


('0', 4, 0), ('C', 4, 1), ('=', 4, 2), ('+', 4, 3) ]

for (text, row, col) in buttons:

button = tk.Button(win, text=text, width=5, height=2, command=lambda t=text: btn_click(t))


button.grid(row=row, column=col)
clear_button = tk.Button(win, text='C', width=5, height=2, command=clear)
clear_button.grid(row=4, column=1)

equal_button = tk.Button(win, text='=', width=5, height=2, command=calculate)


equal_button.grid(row=4, column=2)

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

Enter a array: 10 100 1000


The sum of array [10, 100, 1000, 10000] is: 1110
Ex.No: 08
Date: 07.02.2024

INHERITANCE

PROGRAM:
class Class1: obj.fun2()
def fun1(self): def multiple():

print("Name : ",self.name) obj = Class4()


class Class2(Class1): obj.name=input("Enter Your Name: ")

def fun2(self): obj.age=input("Enter Your Age: ")


print("Age : ",self.age) obj.course=input("Enter Your Course: ")

class Class3: obj.fun1()


def fun3(self): obj.fun3()

print("Age : ",self.age) obj.fun4()


class Class4(Class1, Class3): def multilevel():
def fun4(self): obj = Class5()

print("Course :", self.course) obj.name=input("Enter Your Name: ")


class Class5(Class2): obj.age=input("Enter Your Age: ")

def fun5(self): obj.course=input("Enter Your Course: ")


print("Course :", self.course) obj.fun1()

class Class6(Class1): obj.fun2()


def fun6(self): obj.fun5()

print("Course :", self.course) def hierarchical():


class Class7(Class2,Class1): obj1 = Class2()

def fun7(self): obj1.name=input("Enter Your Name: ")


print("Course :", self.course) obj1.age=input("Enter Your Age: ")

def single(): obj2 = Class6()


obj = Class2() obj2.course=input("Enter Your Course: ")

obj.name=input("Enter Your Name: ") obj1.fun1()

obj.age=input("Enter Your Age: ") obj1.fun2()


obj.fun1() obj2.fun6()
def hybrid(): 6. Exit")
obj = Class7() i=int(input("Enter your choice: "))

obj.name=input("Enter Your Name: ") if i==1:


obj.age=input("Enter Your Age: ") single()

obj.course=input("Enter Your Course: ") elif i==2:


obj.fun1() multiple()

obj.fun2() elif i==3:


obj.fun7() multilevel()

elif i==4:
print("\t\t\t\tInheritance") hierarchical()

print("\t\t\t\t^^^^^^^^^^^") elif i==5:


while True: hybrid()

print("\n1. Simple Inheritance\n\ elif i==6:


2. Multiple Inheritance\n\ print("Exiting program")
3. Multilevel Inheritance\n\ break

4. Hierarchical Inheritance\n\ else:


5. Hybrid Inheritance\n\ print("Error enter a valid number 1-5")
OUTPUT:

Inheritance
1. Simple Inheritance

2. Multiple Inheritance 1. Simple Inheritance


3. Multilevel Inheritance 2. Multiple Inheritance

4. Hierarchical Inheritance 3. Multilevel Inheritance


5. Hybrid Inheritance 4. Hierarchical Inheritance

6. Exit 5. Hybrid Inheritance


Enter your choice: 1 6. Exit

Enter Your Name: Venila Enter your choice: 3


Enter Your Age: 25 Enter Your Name: Hari

Name : Venila Enter Your age: 19


Age : 25 Enter Your Course: BBA
Name : Hari

1. Simple Inheritance Age : 19


2. Multiple Inheritance Course : BBA

3. Multilevel Inheritance
4. Hierarchical Inheritance 1. Simple Inheritance

5. Hybrid Inheritance 2. Multiple Inheritance


6. Exit 3. Multilevel Inheritance

Enter your choice: 2 4. Hierarchical Inheritance


Enter Your Name: Nila 5. Hybrid Inheritance

Enter Your Age: 22 6. Exit


Enter Your Course: BCA Enter your choice: 6

Name : Nila Exiting program


Age : 22

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:")

print("1. Start and End index")


print("2. Start, End, and Step")

print("3. Reverse the list")


print("4. Exit")

i = int(input("Enter your choice: "))


if i == 1:
start = int(input("Enter the start index: "))

end = int(input("Enter the end index: "))


print("Sliced List:", a[start:end])

elif i == 2:
start = int(input("Enter the start index: "))

end = int(input("Enter the end index: "))


step = int(input("Enter the step: "))

print("Sliced List:", a[start:end:step])


elif i == 3:

print("Reversed List:", a[::-1])


elif i == 4:

print("Exiting program.")
break

else:

print("Invalid choice. Please enter 1, 2, 3, or 4.")


OUTPUT:

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

Choose a slicing method: 4. Exit

1. Start and End index Enter your choice: 3

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

Enter your choice: 1


Choose a slicing method:
Enter the start index: 0
1. Start and End index
Enter the end index: 0
2. Start, End, and Step
Sliced List: []
3. Reverse the list
4. Exit
Choose a slicing method:
Enter your choice: 2
1. Start and End index
Enter the start index: 0
2. Start, End, and Step
Enter the end index: 6
3. Reverse the list
Enter the step: 2
4. Exit
Sliced List: ['sophi', 'nithi', 'hari']
Enter your choice: 4
Exiting program.
Ex.No: 10
Date: 19.02.2024

COUNT THE NUMBER OF WORDS

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

The no.of words in the sentence is: 16


Ex.No: 11
Date: 19.02.2024

COPY A FILE

PROGRAM:
import shutil
source_file = input("Enter the path of the source file: ")

destination_file = input("Enter the path of the destination file: ")


try:

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:

Enter the path of the source file: D:\first.txt

Enter the path of the destination file: D:\Ts\second.txt


File copied successfully.
Ex.No: 12
Date: 23.02.2024

CHECK THE PASSWORD IS CORRECT OR NOT

PROGRAM:
def valid(password):

return (

len(password) >= 8 and

any(char.isupper() for char in password) and

any(char.islower() for char in password) and

any(char.isdigit() for char in password) and

any(char in "!@#$%^&*()-_+=~`[]{}|;:'\",.<>?/" for char in password)

while True:

password1 = input("Enter a password: ")

password2 = input("Enter Re-password: ")

if valid(password1):

if valid(password2):

if(password1==password2):

print("Password is valid.")

break

else:

print("Password must be same\n")

else:

print("Re-password is not valid.The password must be contain 8 Characters, Uppercase,


Lowercase, Digit and Special Characters\n")

else:

print("Password is not valid.The password must be contain 8 Characters, Uppercase,


Lowercase, Digit and Special Characters\n")
OUTPUT:
Enter a password: Tharshini

Enter Re-password: Tharshini


Password is not valid. The password must be contain 8 Characters, Uppercase, Lowercase, Digit
and Special Characters

Enter a password: Thars@123


Enter Re-password: Thars@1234

Password must be same

Enter a password: Thars@123

Enter Re-password: Thars@123

Password is valid.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy