0% found this document useful (0 votes)
17 views24 pages

Class Xii Record CSC 2025-2026

The document outlines a series of programming tasks for a Computer Science record at Vani Vidyalaya for the academic year 2025-2026. It includes instructions for writing various programs, such as generating Fibonacci and prime numbers, calculating factorials, creating and searching binary files, and working with CSV files. Each task specifies the expected input, output, and programming requirements, along with examples of how to implement them.
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)
17 views24 pages

Class Xii Record CSC 2025-2026

The document outlines a series of programming tasks for a Computer Science record at Vani Vidyalaya for the academic year 2025-2026. It includes instructions for writing various programs, such as generating Fibonacci and prime numbers, calculating factorials, creating and searching binary files, and working with CSV files. Each task specifies the expected input, output, and programming requirements, along with examples of how to implement them.
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/ 24

VANI VIDYALAYA SR. SEC.

AND JUNIOR COLLEGE


COMPUTER SCIENCE RECORD 2025-2026
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 i) Write a program to input any number from user and calculate factorial of a number.
ii) Write a program to enter the string and to check if it‟s palindrome or not using loop.

PROGRAM: (Factorial)
num=int(input("Enter any number:"))
fact = 1
n=num
while num>1:
fact = fact * num
num-=1
print("Factorial of",n,"is:",fact)
OUTPUT:
Enter any number:6
Factorial of 6 is: 720
ii) Program Palindrome:
msg=input("Enter any string :")
newlist=[]
newlist[:0]=msg
n=len(newlist)
ed=n-1
for i in range(0,n):
if newlist[i]!=newlist[ed]:
print ("Given String is not
a palindrome")
break
if i>=ed:
print ("Given String is a
palindrome")
break
n=n-1
ed = ed – 1

OUTPUT:
Enter any string : madam
Given String is a palindrome

Enter any string : python


Given String is not a palindrome
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 Program to input two numbers and print their LCM and HCF and generate
random number between 1 -6 ,to simulate the dice.

Program:
import random

def roll_dice():
while True:
print("=" * 55)
print("*********************** Rolling Dice ************************")
print("=" * 55)

num = random.randint(1, 6)

if num == 6:
print(f"Hey.....You got {num}. ...... Congratulations!!!!")
elif num == 1:
print(f"Well tried... But you got {num}")
else:
print(f"You got: {num}")

ch = input("Roll again? (Y/N): ")


if ch.lower() == 'n':
break
print("Thanks for playing!!!!!!!!")

def find_hcf_lcm():
X = int(input("Enter first number: "))
Y = int(input("Enter second number: "))

if X > Y:
smaller = Y
else:
smaller = X

for i in range(1, smaller + 1):


if (X % i == 0) and (Y % i == 0):
hcf = i

lcm = (X * Y) // hcf # Using integer division for correct LCM

print(f"The H.C.F. of {X} and {Y} is {hcf}")


print(f"The L.C.M. of {X} and {Y} is {lcm}")

def main():
while True:
print("\n========= Main Menu =========")
print("1. Roll the Dice �")
print("2. Find HCF and LCM")
print("3. Exit")

choice = input("Enter your choice (1/2/3): ")

switch = {
'1': roll_dice,
'2': find_hcf_lcm,
'3': exit
}

func = switch.get(choice, None)

if func:
func()
else:
print("Invalid choice! Please try again.")

if __name__ == "__main__":
main()
OUTPUT:

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 program to implement user defined package „shapes‟ with modules: area &
volume.

Program:

ch = 1
while ch > 0 and ch <= 8:
print("1) Volume of cube")
print("2) Volume of cuboid")
print("3) Volume of cone")
print("4) Volume of cylinder")
print("5) Area of square")
print("6) Area of rectangle")
print("7) Area of circle")
print("8) Area of triangle")

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


if ch == 1:
s = int(input("Enter the side:"))
v = s**3
print("Volume=", v)
elif ch == 2:
l = int(input("Enter the length:"))
b = int(input("Enter the breadth:"))
h = int(input("Enter the height:"))
v=l*b*h
print("Volume=", v)
elif ch == 3:
r = int(input("Enter the radius:"))
h = int(input("Enter the height:"))
v = (3.14 * (r**2) * h) / 3
print("Volume=", v)
elif ch == 4:
r = int(input("Enter the radius:"))
h = int(input("Enter the height:"))
v = 3.14 * (r**2) * h
print("Volume=", v)
elif ch == 5:
s = int(input("Enter the side:"))
a = s**2
print("Area=", a)
elif ch == 6:
l = int(input("Enter the length:"))
b = int(input("Enter the breadth:"))
a=l*b
print("Area=", a)
elif ch == 7:
r = int(input("Enter the radius:"))
a = 3.14 * (r**2)
print("Area=", a)
elif ch == 8:
b = int(input("Enter the base: "))
h = int(input("Enter the height: "))
a = (b * h) / 2
print("Area =", a)
else:
print("Invalid Choice")
break
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 program to create binary file to store Rollno and Name, Search any
Rollno and display name if Rollno found otherwise “Rollno not found”
Program:
import pickle
student=[]
f=open('student.dat','wb')
ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
student.append([roll,name])
ans=input("Add More ?(Y)")
pickle.dump(student,f)
f.close()
f=open('student.dat','rb')
student=[]
while True:
try:
student = pickle.load(f)
except EOFError:
break
ans='y'
while ans.lower()=='y':
found=False
r = int(input("Enter Roll number to search :"))
for s in student:
if s[0]==r:
print("## Name is :",s[1], " ##")
found=True
break
if not found:
print("####Sorry! Roll number not found ####")
ans=input("Search more ?(Y) :")
f.close()
Output:

9. Create a CSV file by entering user id and password, read and search the password
for given user – id.
Program:
import csv

with open("user_info.csv", "w") as obj:


fileobj = csv.writer(obj)

fileobj.writerow(["User Id", "password"])

while(True):

user_id = input("enter id: ")

password = input("enter password: ")

record = [user_id, password]

fileobj.writerow(record)

x = input("press Y/y to continue and N/n to terminate the program\n")

if x in "Nn":

break

elif x in "Yy":

continue

with open("user_info.csv", "r") as obj2:

fileobj2 = csv.reader(obj2)

given = input("enter the user id to be searched\n")

for i in fileobj2:

next(fileobj2)

if i[0] == given:

print(i[1])

break
OUTPUT:
enter id: 1
enter password: vani
press Y/y to continue and N/n to terminate the program
y
enter id: 2
enter password: vidyalaya
press Y/y to continue and N/n to terminate the program
n
enter the user id to be searched
2
vidyalaya
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 to read data from data file in read mode and count the
particular word occurrences in given string, number of times in python.
f=open("test.txt",'r')
read=f.readlines()
f.close()
times=0
times2=0
chk=input("Enter String to search : ")
count=0
for sentence in read:
line=sentence.split()
times+=1
for each in line:
line2=each
times2+=1
if chk==line2:
count+=1
print("The search String ", chk, "is present : ", count, "times")
print(times)
print(times2)
OUTPUT:
Enter String to
search : vani
The search String
vani is present : 1
times
8
8

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
Want 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

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