record2024cs (1)
record2024cs (1)
E)
Marangattupilly P.O 686635
Affl.No: 930115
Ph: 04822-250366
2024-2025
Reg:
LABOUR INDIA GURUKULAM PUBLIC SCHOOL
JUNIOR COLLEGE
MARANGATTUPILLY,KOTTAYAM, KERALA-686635
BONAFIDE CERTIFICATE
2
INDEX
13 Pgm 13: Read text file and move words to another file 21
3
16 Pgm 16: Table creation using python and MySQL 28
4
Program number – 1 : Biggest among three numbers
Date : 12-07-2024
AIM : To write a python script to take input for 3 numbers, check and print the
largest number
Program :
a = int(input("Enter first number"))
b = int(input("Enter second number"))
c = int(input("Enter third number"))
if(a>b and a<c):
biggest = a
elif(b>c):
biggest = b
else:
biggest = c
print ("Biggest number is ",biggest)
Output :
5
Program number – 2 : Table of nth number
Date :12-07-2024
AIM : To write a python script to take input for a number and print its table
Program :
a = int(input("Enter the number"))
for i in range(1,11):
print (i, ‘X’, a,'=',i*a)
Output :
6
Program number – 3 : To print factorial
Date : 19-07-2024
AIM : To write a python script to take input for a number and print its factorial
Program :
a = int(input("Enter the number"))
fact = 1
for i in range(1,a+1):
fact = fact * i
print ("Factorial of ",a," is ",fact)
Output :
7
Program number – 4 : To check prime number
Date :19-07-2024
AIM : To input a number and check the number is prime or not
Program :
num = int(input("Enter the number "))
if num > 1:
for i in range(2, int(num/2)+1):
if (num % i) == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
else:
print(num, "is not a prime number")
Output :
8
Program number – 5 : Find sum of elements of a list
Date : 09-08-2024
AIM : To find the sum of elements of agiven list
Program :
list1 = [11, 5, 17, 18, 23]
total = 0
for ele in range(0, len(list1)):
total = total + list1[ele]
Output :
9
Program number – 6 : Count of vowels in a string
Date :09-08-2024
AIM : To find the total number of vowels in a given string
Program :
def vowel_count(str1):
count = 0
vowel = "aeiouAEIOU"
if alphabet in vowel:
count = count + 1
vowel_count(str1)
10
Output :
11
Program number – 7 : Search in a string
Date : 23-08-2024
AIM : To check a word is present in a string or not.
Program :
words = string1.split()
if string2 in words:
print (string2, "is present in above sentense")
else:
print (string2, "is not present in above sentense")
Output :
12
Program number – 8 : Random number generator
Date : 23-08-2024
AIM : To write a program to generate a random number between 0 and 9
Program :
print(random.randint(0,9))
Output :
13
Program number – 9 : Read text file and count words
Date : 23-08-2024
AIM : To Read a text file and display the number of words in the file
Program :
file = open("data.txt", "r")
data = file.read()
words = data.split()
Output :
14
Program number – 10: Read text file and add # to each word
Date : 13-09-2024
AIM : To read a text file line by line and display each word separated by a #
Program :
filein = open("data.txt",'r')
for line in filein:
word= line .split()
for w in word:
print(w + '#',end ='')
print()
filein.close()
Output :
15
Program number – 11 : Create and update binary file
Date : 13-09-2024
AIM : To Create a binary file with roll number, name and marks. Input a roll number and
update the marks
Program :
import pickle
#creating the file and writing the data
f=open("records.dat", "wb")
#list index 0 = roll number
#list index 1 = name
#list index 2 = marks
pickle.dump([1, "Wakil", 90], f)
pickle.dump([2, "Tanish", 80], f)
pickle.dump([3, "Priyashi", 90], f)
pickle.dump([4, "Kanupriya", 80], f)
pickle.dump([5, "Ashutosh", 85], f)
f.close()
17
Output :
18
Program number – 12 : Read text file and move words to another file
Date : 13-09-2024
AIM : To Read a file remove all the lines that contain the character `a' in a file and write
it to another file.
Program :
myfile = open("data.txt", "r")
newfile = open("data_new.txt", "w")
line = " "
while line:
line = myfile.readline()
if 'a' not in line:
newfile.write(line)
myfile.close()
newfile.close()
print("Successfully created")
19
Output :
20
Program number – 13 : Insert data to binary file
Date : 04-10-2024
AIM : To write a Python program to write student data in binary file python.
Program :
import pickle
def write():
file = open("binary.dat","wb")
records = []
x =21
while(x == 21):
rno = int(input("Enter Roll number: "))
name = input("Enter Name: ")
grade = input("Enter Grade: ")
marks = int(input("Enter Marks: "))
data = [rno,name,grade,marks]
records.append(data)
ch = input("Do you want to ad more records: ")
if ch == 'n':
break
pickle.dump(records,file)
file.close()
write()
21
Output :
22
Program number – 14 : Implement Stack Using List of Numbers
Date : 04-10-2024
AIM : To write a python script to implement stack using list (Push & Pop
Operation) using numbers.
Program :
def isEmpty(s):
if len(s)==0:
return True
else:
return False
def push(s,item):
s.append(item)
top=len(s)-1
def pop(s):
if isEmpty(s):
return 'Underflow occurs'
else:
val=s.pop()
if len(s)==0:
top=None
else:
top=len(s)-1
return val
def show(s):
if isEmpty(s):
print('no item found')
else:
t=len(s)-1
print('(TOP)',end='')
while(t>=0):
print(s[t],'<==',end='')
t=t-1
print()
23
s=[]
top=None
while True:
print('****** STACK IMPLEMENTATION USING LIST ******')
print('1: Add Number')
print('2: Remove Number')
print('3: Show Stack')
print('0: Exit')
ch=int(input('Enter choice:'))
if ch==1:
val=int(input('Enter no to push:'))
push(s,val)
elif ch==2:
val=pop(s)
if val=='Underflow':
print('Stack is empty')
else:
print('\nDeleted item is:',val)
elif ch==3:
show(s)
elif ch==0:
print('Bye')
break
24
Output :
25
Program number – 15 : Implement Stack Using List of Names
Date : 04-10-2024
AIM : To write a python script to implement stack using list (Push & Pop
Operation) using numbers.
Program :
def isEmpty(s):
if len(s)==0:
return True
else:
return False
def push(s,item):
s.append(item)
top=len(s)-1
def pop(s):
if isEmpty(s):
return 'Underflow occurs'
else:
val=s.pop()
if len(s)==0:
top=None
else:
top=len(s)-1
return val
def show(s):
if isEmpty(s):
print('no item found')
else:
t=len(s)-1
print('(TOP)',end='')
while(t>=0):
print(s[t],'<==',end='')
t=t-1
print()
s=[]
top=None
while True:
print('****** STACK IMPLEMENTATION USING LIST ******')
print('1: PUSH')
print('2: POP')
26
print('3: Show')
print('0: Exit')
ch=int(input('Enter choice:'))
if ch==1:
val= input('Enter name to push:')
push(s,val)
elif ch==2:
val=pop(s)
if val=='Underflow':
print('Stack is empty')
else:
print('\nDeleted item is:',val)
elif ch==3:
show(s)
elif ch==0:
print('Bye')
break
Output :
27
Program number – 16 : Table creation using python and MySQL
Date : 23-10-2024
AIM : To write a python script to create table using MySQL.
Program :
import mysql.connector
Output :
28
Program number – 17 : Inserting records into table using python and
MySQL
Date : 23-10-2024
AIM : To write a python script to insert records into MySQL table.
Program :
import mysql.connector
29
Output :
30
Program number – 18 : Updating records in table using python and
MySQL
Date : 23-10-2024
AIM : To write a python script to update records in MySQL table.
Program :
import mysql.connector
Output :
31
Program number – 19 : Deleting records from table using python and
MySQL
Date : 01-11-2024
AIM : To write a python script to delete records from python table.
Program :
import mysql.connector
Output :
32
Program number – 20 : Fetching records from table using python and
MySQL
Date : 01-11-2024
-1 AIM : To write a python script to fetch records from MySQL table.
Program :
import mysql.connector
33
Output :
34
Program number – 21 : Fetching records from table using python and MySQL
Date : 01-11-2024
AIM : To write a python script to fetch records from MySQL table with condition.
Program :
import mysql.connector
Output :
35
Program number – 22 : Joining 2 tables using python and MySQL
Date : 08-11-2024
Program :
import mysql.connector
result = cursor.fetchall()
print(result)
36
Output :
37
Program number – 23 : MySQL Commands – Simple Queries.
Date : 09-11-2022
AIM : To execute simple MySQL queries.
Script :
10.1 – select all from table ‘EMPLOYEE’ in database ‘mydb’
USE mydb;
SELECT * FROM EMPLOYEE ;
10.2 – select selected columns from table ‘EMPLOYEE’ in database ‘mydb’
USE mydb;
SELECT EMP_ID, FIRST_NAME FROM EMPLOYEE;
38
Output :
39
Program number – 24 : MySQL Commands – Selection Queries.
Date : 08-11-2024
AIM : To execute selection based MySQL queries.
Script :
11.1 – select ‘FIRST_NAME’ from table ‘EMPLOYEE’ in database ‘mydb’ with age
> 30.
USE mydb;
SELECT FIRST_NAME FROM EMPLOYEE WHERE AGE>30;
40
Output :
41
Program number – 25 : MySQL Commands – Functions and Grouping.
Date : 08-11-2024
Script :
12.1 - select average value of ‘AGE’ from table ‘EMPLOYEE’ in database ‘mydb’.
USE mydb;
SELECT AVG(AGE) FROM EMPLOYEE;
12.2 - total count of employees from table ‘EMPLOYEE’ in database ‘mydb’ grouped by
‘AGE’.
USE mydb
SELECT AGE, COUNT(*) FROM EMPLOYEE GROUP BY AGE;
‘EMPLOYEE’
USE mydb
SELECT UPPER(FIRST_NAME) FROM EMPLOYEE ;
42
Output :
43