Class Xii Record CSC 2025-2026
Class Xii Record CSC 2025-2026
Pgm no : 1
Question :
Program:
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
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}")
def find_hcf_lcm():
X = int(input("Enter first number: "))
Y = int(input("Enter second number: "))
if X > Y:
smaller = Y
else:
smaller = X
def main():
while True:
print("\n========= Main Menu =========")
print("1. Roll the Dice �")
print("2. Find HCF and LCM")
print("3. Exit")
switch = {
'1': roll_dice,
'2': find_hcf_lcm,
'3': exit
}
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:
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")
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
while(True):
fileobj.writerow(record)
if x in "Nn":
break
elif x in "Yy":
continue
fileobj2 = csv.reader(obj2)
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]}
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
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'}
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.
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