0% found this document useful (0 votes)
13 views19 pages

XII CSC REC 2024-25.docx-1

The document outlines a Computer Science record for Vani Vidyalaya for the academic year 2024-2025, detailing various programming tasks and exercises. It includes instructions for formatting, a series of programming questions related to data structures, file handling, and SQL connectivity. Each task is accompanied by example outputs and specific coding requirements.

Uploaded by

nivashstark765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views19 pages

XII CSC REC 2024-25.docx-1

The document outlines a Computer Science record for Vani Vidyalaya for the academic year 2024-2025, detailing various programming tasks and exercises. It includes instructions for formatting, a series of programming questions related to data structures, file handling, and SQL connectivity. Each task is accompanied by example outputs and specific coding requirements.

Uploaded by

nivashstark765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

VANI VIDYALAYA SR. SEC.

AND JUNIOR COLLEGE


COMPUTER SCIENCE RECORD 2024-2025
Instructions :
● Before you start check if have taken the correct record.(200 pgs one side ruled
WITHOUT GRAPH)
● Write the program on the ruled side with blue pen and output on the blank side in pencil

Pgm no : 1
Question :

Program:

● Write in the same format mentioned above


● Fill the page numbers, index , bonafide( only name)
● Submit on the reopening day
SLNO QUESTION
1 Write a menu driven program to
1.Print Fibonnacci series of N numbers
2.Print Prime numbers between the limits
OUTPUT:

1. Fibonacci series
2.Prime numbers
3.Exit
Enter your choice(1 to 3)...
1
How many terms?4
Fibonacci series:
0
1
1
2

1. Fibonacci series
2.Prime numbers
3.Exit
Enter your choice(1 to 3)...
2
Enter two limits:20
40
Prime numbers between 20 & 40 are:
23
29
31
37

1. Fibonacci series
2.Prime numbers
3.Exit
Enter your choice(1 to 3)...

2 Write a program that reads a line and prints its statistics like:
Number of uppercase letters:
Number of lowercase letters:
Number of alphabets:
Number of digits:

OUTPUT:
Enter a line A Binary File named EMP.DAT has 25 employees details
Number of uppercase letters: 9
Number of lowercase letters: 32
Number of alpabets: 41
Number of digits: 2

3 Write a program to create a binary file and search records from the file.
import pickle
def create():
f=open("students.dat",'ab')
opt = 'y'
while opt == 'y':
rollno=int(input('Enter rollnumber:'))
name = input('Enter name:')
l=[rollno,name]
pickle.dump(l,f)
opt=input('Do you want to add another student [y/n]')
f.close()
def search():
f=open('students.dat','rb')
no=int(input("Enter roll no of student to search:"))
found=0
try:
while True:
s=pickle.load(f)
print(s)
if s[0] == no:
print("The searched rollno is found and details are:",s)
found =1
break
except:
f.close()
if found==0:
print("The searched rollno is not found")

print("Select the option :")


print("1.Add records")
print("2.Search record")
print("3.Exit")
ch=int(input("Enter the option:"))
if ch == 1:
create()
if ch == 2:
search()
if ch == 3:
exit()

OUTPUT:

4 Write a menu driven program that inputs a string and


1.Creates an encrypted string by embedding a symbol after each character.
2. Find if the string is Palindrome

def encrypt(sttr,enkey):
return enkey.join(sttr)

def decrypt(sttr,enkey):
return sttr.split(enkey)

def palindrome(str):
length=len(str)
mid=int(length/2)
rev=-1
for a in range(mid):
if str[a] == str[rev]:
a+=1
rev-=1
else:
print(str,"not a palindrome")
break
else:
print(str,"Is a Palindrome")

mainstring=input("Enter main string:")


encryptstr=input("Enter ecryption string:")
enstr=encrypt(mainstring,encryptstr)
delst=decrypt(enstr,encryptstr)

destr="".join(delst)
print("The encrypted string is: ",enstr)
print("string after decryption is :",destr)

string = input("Enter a string to find if Palindrome:")


palindrome(string)

OUTPUT:
Enter main string:Comma Seperated Files
Enter ecryption string:@#
The encrypted string is: C@#o@#m@#m@#a@#
@#S@#e@#p@#e@#r@#a@#t@#e@#d@# @#F@#i@#l@#e@#s
string after decryption is : Comma Seperated Files
Enter a string to find if Palindrome:MADAM
MADAM Is a Palindrome

5 Program to create CSV file and store empno,name,salary and search any
empno and display name,salary and if not found appropriate message.
Output:

Enter Employee Number 1001


Enter Employee Name Rishab
Enter Employee Salary :43434
## Data Saved... ##
Add More ?no
Enter Employee Number to search :1001
============================
NAME : Rishab
SALARY : 43434
Enter Employee Number to search :23
==========================
EMPNO NOT FOUND
==========================
Search More ? (Y)n

6 Write a python program to implement searching methods based on user choice using a
list data-structure. (linear & binary)
OUTPUT:

7 Write a program to create two text files and merge the contents into “mergefile.txt”.
program1()
program2()
program3()
display_merge()

OUTPUT:

8 Write a function to that accepts an integer list as argument and shift all odd numbers to
the left and even numbers to the right of the list without changing the order
# Shifting odd and even values
def shift(a,n):
c=0
for i in range(n):
if a[i]%2!=0:
x=a.pop(i)
a.insert(c,x)
c+=1

a=[ ]
n=int(input("How many values:"))
print("Enter",n,"values:")
for i in range(n):
a.append(int(input()))
print("List values before shifting:",a)
shift(a,n)
print("List values after shifting:",a)

OUTPUT:
How many values:5
Enter 5 values:
23
12
66
34
13
List values before shifting: [23, 12, 66, 34, 13]
List values after shifting: [23, 13, 12, 66, 34]
>>>

9 Write a program to print the longest and shortest string in a tuple.


#Find long and short string in a tuple
def find_long(s,n):
long=short=s[0]
for a in s:
if len(a)>len(long):
long=a
elif len(a) <len(short):
short = a
print("Longest string is :",long)
print("Shortest string is :",short)

def find_small(s,n):
great=small=s[0]
for a in s:
if a > great:
great = a
elif a< small:
small = a
print("Greatest string is :",great)
print("Smallest string is :",small)

t=()
n=int(input("How many strings:"))
print("Enter ",n,"Strings:")
for i in range(n):
t += (input(),)
find_long(t,n)
find_small(t,n)

OUTPUT:
How many strings:4
Enter 4 Strings:
Chennai
Delhi
Mumbai
Kolkata
Longest string is : Chennai
Shortest string is : Delhi
Greatest string is : Mumbai
Smallest string is : Chennai

10 Write a program to create a dictionary game name as key and a list with elements like
Player name, Country name and Points.. Also display the same.

OUTPUT:
How many Games:2
Enter the game:CRICKET
Enter Player name:DHONI
Enter country name :INDIA
Enter the points:98
Enter the game:FOOTBALL
Enter Player name:RONALDO
Enter country name :PORTUGAL
Enter the points:98
----------------------------------------------------------------------------------------------------
Records in Dictionary
{'CRICKET': ['DHONI', 'INDIA', 98], 'FOOTBALL': ['RONALDO', 'PORTUGAL',
98]}
----------------------------------------------------------------------------------------------------

Records in ascending order of game:


CRICKET ['DHONI', 'INDIA', 98]
----------------------------------------------------------------------------------------------------
FOOTBALL ['RONALDO', 'PORTUGAL', 98]
----------------------------------------------------------------------------------------------------

11 Write a program to count a total number of lines and count the total number of lines
starting with ‘l’, ‘n’, and ‘t’. (Consider the mergefile.txt file)

OUTPUT:

12 Write a program with functions to create a text file called “myself.txt” , store
information and print the same. Also write another function to copy all the lines to a
new file called myself2.txt which are not having the line which have letter ‘S’ and
display the new file.

def create_file():
f=open("myself.txt","w")
print("Enter about yourself and 'exit' to stop")
while True:
s=input()
if s.upper() == 'EXIT':
break
f.write(s)
f.write('\n')
f.close()

def print_file(a):
f=open(a,"r")
s=" "
while s:
s=f.readline()
print(s,end=" ")
f.close()

def copy_file():
f1=open("myself.txt","r")
f2=open("myself2.txt","w")
s=" "
count = 0
while s:
s=f1.readline()
if 's'.upper() in s.upper():
pass
else:
f2.write(s)
f1.close()
f2.close()

create_file()
print("CONTENT OF MYSELF.TXT:")
print_file("myself.txt")
copy_file()
print("CONTENT OF MYSELF2.TXT:")
print_file("myself2.txt")

OUTPUT :

Enter about yourself and 'exit' to stop


I am Anitha
I am a student of class 12
I study in a CBSE School
exit
CONTENT OF MYSELF.TXT:
I am Anitha
I am a Computer Science Teacher
I work for a CBSE School
CONTENT OF MYSELF2.TXT:
I am Anitha
13 Write a program to create a CSV file and also display the contents of the file

from csv import writer


def pro4():
#Create Header First
f = open("students.csv","w",newline='\n')
dt = writer(f)
dt.writerow(['Student_ID','StudentName','Score'])
f.close()
#Insert Data
f = open("students.csv","a",newline='\n')
while True:
st_id= int(input("Enter Student ID:"))
st_name = input("Enter Student name:")
st_score = input("Enter score:")
dt = writer(f)
dt.writerow([st_id,st_name,st_score])
ch=input("Want to insert More records?(y or Y):")
ch=ch.lower()
if ch !='y':
break
print("Record has been added.")
f.close()

pro4()

import csv
data = csv.DictReader(open("students.csv"))
print("CSV file as a dictionary:\n")
for row in data:
print(row)

OUTPUT
Enter Student ID:1
Enter Student name:AAA
Enter score:78
Want to insert More records?(y or Y):Y
Record has been added.
Enter Student ID:3
Enter Student name:HHH
Enter score:67
Want to insert More records?(y or Y):Y
Record has been added.
Enter Student ID:8
Enter Student name:TTT
Enter score:89
Want to insert More records?(y or Y):N
CSV file as a dictionary:

{'Student_ID': '1', 'StudentName': 'ABHA', 'Score': '78'}


{'Student_ID': '3', 'StudentName': 'VINI', 'Score': '67'}
{'Student_ID': '8', 'StudentName': 'TANU', 'Score': '89'}

Content of the Students.csv file


Student_ID,StudentName,Score
1,ABHA,78
3,VINI,67
8,TANU,89

14 Write a program to create a binary file and display the records whose marks are > 95.
import pickle
def search_95plus():
f = open("marks.dat","ab")
while True:
rn=int(input("Enter the rollno:"))
sname=input("Enter the name:")
marks=int(input("Enter the marks:"))
rec=[]
data=[rn,sname,marks]
rec.append(data)
pickle.dump(rec,f)
ch=input("Wnat more records?Yes:")
if ch.lower() not in 'yes':
break
f.close()
f = open("marks.dat","rb")
cnt=0
try:
while True:
data = pickle.load(f)
for s in data:
if s[2]>95:
cnt+=1
print("Record:",cnt)
print("RollNO:",s[0])
print("Name:",s[1])
print("Marks:",s[2])
except Exception:
f.close()
search_95plus()

import pickle
def count_records():
f = open("marks.dat","rb")
cnt=0
try:
while True:
data = pickle.load(f)
for s in data:
cnt+=1
except Exception:
f.close()
print("The file has ", cnt, " records.")
count_records()

Output:
Enter the rollno:1
Enter the name:AAA
Enter the marks:56
Wnat more records?Yes:Y
Enter the rollno:2
Enter the name:BBB
Enter the marks:78
Wnat more records?Yes:Y
Enter the rollno:3
Enter the name:CCC
Enter the marks:98
Wnat more records?Yes:N
Record: 1
RollNO: 3
Name: CCC
Marks: 98
The file has 3 records.

15. Write a program to implement stack operations in Python.

Program 7.1 - Pgno 283


16 Write a python -SQL connectivity program to create a table.
import mysql.connector
db_connection =
mysql.connector.connect(host="localhost",user="root",passwd="hello123",database="sy
s")
db_cursor = db_connection.cursor()
db_cursor.execute("DROP TABLE employee")
#Here creating table as employee with primary key
db_cursor.execute("CREATE TABLE employee(id INT PRIMARY KEY, name
VARCHAR(255), salary INT(6))")
print("Table Created")

Output:
Table Created

17. Write a python -SQL connectivity program to insert data into the table.

import mysql.connector
db_connection =
mysql.connector.connect(host="localhost",user="root",passwd="hello123",database="sy
s")
db_cursor = db_connection.cursor()
#inserting data records in a table
ch='y'
while ch =='y':
id=int(input("Enter id number:"))
name = input("Enter name:")
salary= int(input("Enter salary"))
db_cursor.execute(" INSERT INTO employee VALUES (%s, %s, %s)",
(id,name,salary))
#Execute cursor and pass query of employee and data of employee
db_connection.commit()
print(db_cursor.rowcount, "Record Inserted")
ch=input("Do you want to enter data:[y/n]")

Output:
Enter id number:1
Enter name:Anu
Enter salary346565
1 Record Inserted
Do you want to enter data:[y/n]y
Enter id number:2
Enter name:Arav
Enter salary654745

18. Write a python -SQL connectivity program to Update data into the table.

import mysql.connector
db_connection =
mysql.connector.connect(host="localhost",user="root",passwd="hello123",database="sy
s")
db_cursor = db_connection.cursor()
#Record Updation
print("Record Updation:")
rno = int(input("Enter Record Number to be Updated:"))
name = input("Enter name:")
salary= int(input("Enter salary"))
sqlFormula = "UPDATE employee SET name = %s, salary = %s WHERE id = %s"
db_cursor.execute(sqlFormula,(name,salary,rno))
print ("record updated")
db_connection.commit()

Output:
Record Updation:
Enter Record Number to be Updated:1
Enter name:Anu
Enter salary100000

Record updated

19. Perform all the operations with reference to table ‘students’ through MySQL-Python
connectivity.

import mysql.connector as ms
db=ms.connect(host="localhost",user="root",passwd="hello123",database='sys')
cn=db.cursor()
def insert_rec():
try:
while True:
rn=int(input("Enter roll number:"))
sname=input("Enter name:")
marks=float(input("Enter marks:"))
gr=input("Enter grade:")
cn.execute("insert into students values({},'{}',{},'{}')".format(rn,sname,marks,gr))
db.commit()
ch=input("Want more records? Press (N/n) to stop entry:")
if ch in 'Nn':
break
except Exception as e:
print("Error", e)

def update_rec():
try:
rn=int(input("Enter rollno to update:"))
marks=float(input("Enter new marks:"))
gr=input("Enter Grade:")
cn.execute("update students set marks={},grade='{}' where
rno={}".format(marks,gr,rn))
db.commit()
except Exception as e:
print("Error",e)

def delete_rec():
try:
rn=int(input("Enter rollno to delete:"))
cn.execute("delete from students where rno={}".format(rn))
db.commit()
except Exception as e:
print("Error",e)

def view_rec():
try:
cn.execute("select * from students")
myresult = cn.fetchall()
print(myresult)
except Exception as e:
print("Error",e)

while True:
print("MENU\n1. Insert Record\n2. Update Record \n3. Delete Record\n4. Display
Record \n5. Exit")
ch=int(input("Enter your choice<1-4>="))
if ch==1:
insert_rec()
elif ch==2:
update_rec()
elif ch==3:
delete_rec()
elif ch==4:
view_rec()
elif ch==5:
break
else:
print("Wrong option selected")

20 SQL

Pg no Q.No

532 19 Queries a to d

533 20 Queries a to e

534 21 Queries i to iv

Write the table on the left hand side ( Blank Page)

Write Question and query on the ruled side.

You might also like