Professional Documents
Culture Documents
Aakarshit Gupta Practical File 12th B
Aakarshit Gupta Practical File 12th B
Aakarshit Gupta Practical File 12th B
VIDYA PEETH
ROLL NO : 13
SUBJECT : COMPUTER SCIENCE
3. Remove all the lines that contain the character “a” in a file and
write it into another file.
4. Create a binary file with name & Roll no. Search for a given roll no.
& display the name, if not found display appropriate message.
5. Create a binary file with roll no. , name, marks. Input a roll no. &
update the marks.
6. Write a random no. generator that generates random no. between 1&
6 [must be integers] both included.
12. Write a program to find largest & second largest element from the
numeric list entered by the user.
a=fh.readline()
words=a.split()
for j in words:
item.append(j)
if a =="":
break
print("#".join(item))
Output:
2. Write a program to read a file and display no. of vowels,
consonants, lowercase, and uppercase & characters in the file.
Output:
3. Remove all the lines that contain the character “a” in a file and
write it into another file.
Output:
4. Create a binary file with name & Roll no. Search for a given roll no. & display the
name, if not found display appropriate message.
Output:
5. Create a binary file with roll no. , name, marks. Input a roll no. & update the marks.
import pickle
def Write():
f = open("Studentdetails.dat", 'wb')
while True:
r =int(input ("Enter Roll no : "))
n = input("Enter Name : ")
m = int(input ("Enter Marks : "))
record = [r,n,m]
pickle.dump(record,f)
ch = input("Do you want to enter more ?(Y/N)")
if ch in 'Nn':
break
f.close()
def Read():
f = open("Studentdetails.dat",'rb')
try:
while True:
rec=pickle.load(f)
print(rec)
except EOFError:
f.close()
def Update():
f = open("Studentdetails.dat", 'rb+')
rollno = int(input("Enter roll no whose marks you want to update"))
try:
while True:
pos=f.tell()
rec = pickle.load(f)
if rec[0]==rollno:
um = int(input("Enter Update Marks:"))
rec[2]=um
f.seek(pos)
pickle.dump(rec,f)
#print(rec)
except EOFError:
f.close()
Write()
Read()
Update()
Read()
Output:
6. Write a random no. generator that generates random no. between 1& 6 [must be
integers] both included.
Output:
7. Write a program to implement a stack using list.
Output:
8. Write a program to perform insertion sort..
def insertionSort(arr):
n = len(arr) # Get the length of the array
if n <= 1:
return # If the array has 0 or 1 element, it is already sorted, so return
for i in range(1, n): # Iterate over the array starting from the second element
key = arr[i] # Store the current element as the key to be inserted in the right position
j = i-1
while j >= 0 and key < arr[j]: # Move elements greater than key one position ahead
arr[j+1] = arr[j] # Shift elements to the right
j -= 1
arr[j+1] = key # Insert the key in the correct position
Output:
list1 = [5, 3, 8, 6, 7, 2]
print("The unsorted list is: ", list1)
# Calling the bubble sort function
print("The sorted list is: ", bubble_sort(list1))
Output:
list1 = [1 ,3, 5, 4, 7, 9]
key = 7
n = len(list1)
res = linear_Search(list1, n, key)
if(res == -1):
print("Element not found")
else:
print("Element found at index: ", res) )
Output:
Output:
12. Write a program to find largest & second largest element from the numeric list
entered by the user.
def find_largest_and_second_largest(list1):
largest = list1[0]
second_largest = list1[1]
for i in range(2, len(list1)):
if list1[i] > largest:
second_largest = largest
largest = list1[i]
elif list1[i] > second_largest:
second_largest = list1[i]
return largest, second_largest
Output:
Output:
Output:
A
BC
DEF
GHIJ
KLMNO
PQRSTU
15. Write a program to check for palindrome.
Output:
Output
2. Update table to modify data
Output
Output
4. Descending order
Max command
Min command.
Sum command
Average command
6. Create two table employee and salary. Add data into these
tables and create 4 SQL queries including joins.
.
Equi join
Right outer join
Natural join
Output
9. WAP to display Name and employee of all employees whose job assigned
is Manager order employer code in descending order.