CS Project File.
CS Project File.
˚
Sr. No. Particulars
1 Acknowledgment
2 Certificate
3 Program 1
4 Program 2
5 Program 3
6 Program 4
7 Program 5
8 Program 6
9 Program 7
10 Program 8
11 Program 9
12 Program 10
13 Program 11
14 Program 12
15 Program 13
16 Program 14
17 Program 15
18 Program 16
19 Program 17
20 Program 18
21 Program 19
22 Program 20
23 Thanking
⊹࣪
˖ACKNOWLEDGEMENTˊˎ-
I would like to express my special thanks to my teacher
Ms. Priyanka Singh and our principal ma’am, who gave
me the golden opportunity to make this project. I would
also like to thank my computer teacher for providing
guidance and support throughout the process of
completion of this project.
Additionally, I would like to thank my parents
and my fellow mates for their unwavering support and
encouragement.
⊹ ࣪ ˖CERTIFICATEˊˎ-
This is to certify that Aaraghya B., a student
of class XII-A has completed her computer
science project file under my supervision.
She has taken proper care and shown utmost
sincerity in completing this project.
I certify that this project
is upto my expectations & as per the
guidelines issued by CBSE.
⊹ ࣪ ˖Program 01ˊˎ-
✦Write a Python program to check whether the number
entered by the user is a prime number or not.
num=int(input("enter a number:"))
if num<=1:
print(num,"is not a prime number")
else:
isprime=True
for i in range(2,num):
if num%i==0:
isprime=False
break
else:
print(num,"is a prime number")
if not isprime:
print(num,"is not a prime number")
ᯓ Output 1 ᯓ
⊹ ࣪ ˖Program 02ˊˎ-
★Write a Python program to check whether an element is present in
a list or not. If it is present, display its index, otherwise print an
appropriate message.
a = input("Enter the elements of the list separated by
spaces: ").split()
element = input("Enter the element to check: ")
if element in a:
print("The element", element, "is present at index",
a.index(element))
else:
print("The element", element, "is not present in the
list")
ᯓ Output 2 ᯓ
⊹ ࣪ ˖Program 3ˊˎ-
★Write a function in python to find the factorial of a number
entered by the user.
def factorial(n):
result = 1
for i in range(1, n + 1):
result *= i
return result
ᯓ Output 3 ᯓ
⊹ ࣪ ˖Program 4ˊˎ-
★Write a python program by defining a function to input 2
numbers from the user & return the result of following Arithmetic
operators like +,-,*,%,//. In a single variable
def operations(a, b):
return a + b, a - b, a * b, a % b, a // b
result = operations(x, y)
print("Results (Addition, Subtraction, Multiplication, Modulus, Floor
Division):", result)
ᯓ Output 4 ᯓ
⊹ ࣪ ˖Program 5ˊˎ-
★Write a program to define a function EvenSum(numbers) and add
all the numbers of the list that are at even positions of the list.
(Numebrs will be entered by the user)
def EvenSum(numbers):
even_sum = 0
for i in range(len(numbers)):
if i % 2 == 0:
even_sum += numbers[i]
return even_sum
numbers = input("Enter the numbers separated by spaces: ").split()
numbers = [int(num) for num in numbers]
result = EvenSum(numbers)
print("The sum of numbers at even positions is:", result)
ᯓ Output 5 ᯓ
⊹ ࣪ ˖Program 6 [a]ˊˎ-
★ Write a program to define a function that makes a number as
argument & calculate cube for it. The function does not return a
value if there is no value passed to the function, the function should
calculate the cube of 2.
def cube(num=2):
print(num ** 3)
cube()
cube(4)
ᯓ Output 6(a)ᯓ
⊹ ࣪ ˖Program 6 [b]ˊˎ-
★Write a program to define a function that takes two string arguments
and return True, if both arguments are equal, otherwise False.
print(check_equal("hello", "hello"))
print(check_equal("hello", "world"))
ᯓ Output 6(b)ᯓ
⊹ ࣪ ˖Program 7ˊˎ-
★ Write a python program that receives 2 parameters x & n,
compute and return the result as x^n.
def power(x, n):
return x ** n
print(power(2, 3))
print(power(5, 2))
ᯓ Output 7 ᯓ
⊹ ࣪ ˖Program 8ˊˎ-
★Write a program to define a function and search the frequency of a
word entered by the user in the string.
def word_frequency(text, word):
return text.split().count(word)
⊹ ࣪ ˖Program 9ˊˎ-
★ Sohan wants to play a ludo game, but he has lost his dice. Help
Sohan to resolve the problem. Write a code to generate the random
numbers between 1 & 6 using random library.
import random
def roll():
r=random.randint(1,6)
return r
droll=roll()
print("you rolled a:",droll)
ᯓ Output 9 ᯓ
⊹ ࣪ ˖Program 10ˊˎ-
★Write a program to enter the following records in a binary file:
Item No integer
Item_Name string
Qty integer
Price float
Number of records to be entered should be accepted from
the user. Read the fi le to display the records in the following
format:
Item No:
Item Name :
Quantity:
Price per item:
Amount: ( to be calculated as Price * Qty)
import pickle
def read_from_file(filename):
with open(filename, 'rb') as file:
try:
while True:
record = pickle.load(file)
amount = record['Price'] * record['Qty']
print("Item No:", record['Item No'])
print("Item Name:", record['Item Name'])
print("Quantity:", record['Qty'])
print("Price per item:", record['Price'])
print("Amount:", amount, "\n")
except EOFError:
pass
filename = "items.dat"
num_records = int(input("Enter number of records to be entered: "))
write_to_file(filename, num_records)
print("\nDisplaying the records:")
read_from_file(filename)
ᯓ Output 10 ᯓ
⊹ ࣪ ˖Program 11ˊˎ-
★Write a program in python to replace a character by another
character in a file “story.txt”.
filename = "story.txt"
old_char = input("Enter character to replace: ")
new_char = input("Enter new character: ")
with open(filename, 'r') as file:
content = file.read()
newcontent = content.replace(old_char, new_char)
with open(filename, 'w') as file:
file.write(newcontent)
if content != newcontent:
print("Replaced", old_char, "with", new_char, "in the file.")
ᯓ Output 11 ᯓ
⊹ ࣪ ˖Program 12ˊˎ-
★: Write a program in python to replace all word “the” by another
word “them” in a file “peom.txt”.
filename = "poem.txt"
old_word = "the"
new_word = "them"
if content != new_content:
print("Replaced", old_word, "with", new_word, "in the file.")
ᯓ Output 12 ᯓ
⊹ ࣪ ˖Program 13ˊˎ-
★Write a program in python to count those words whose length is
more than 7 characters in a file “story.txt”.
filename = "story.txt"
count = 0
words = content.split()
for word in words:
if len(word) > 7:
count += 1
ᯓ Output 13 ᯓ
⊹ ࣪ ˖Program 14ˊˎ-
★: Write a program to add/insert records in file “data.csv”. Structure
of a record is roll number, name and class.
import csv
filename = "data.csv"
ᯓ Output 14 ᯓ
⊹ ࣪ ˖Program 15ˊˎ-
★: Write a menu-driven program which shows all operations on
Binary file.
1. Add Record
2. Display All Record
3. Display Specific Record
4. Modify Record
5. Delete Record
import pickle
def add_record(filename):
with open(filename, 'ab') as file:
roll_no = int(input("Enter roll number: "))
name = input("Enter name: ")
class_name = input("Enter class: ")
record = {'Roll No': roll_no, 'Name': name, 'Class': class_name}
pickle.dump(record, file)
print("Record added.")
def display_all_records(filename):
try:
with open(filename, 'rb') as file:
while True:
record = pickle.load(file)
print("Roll No:", record['Roll No'], "Name:",
record['Name'], "Class:", record['Class'])
except EOFError:
pass
def display_specific_record(filename):
roll_no = int(input("Enter roll number to search: "))
try:
with open(filename, 'rb') as file:
while True:
record = pickle.load(file)
if record['Roll No'] == roll_no:
print("Roll No:", record['Roll No'], "Name:",
record['Name'], "Class:", record['Class'])
return
except EOFError:
pass
print("Record not found.")
def modify_record(filename):
roll_no = int(input("Enter roll number to modify: "))
records = []
modified = False
try:
with open(filename, 'rb') as file:
while True:
record = pickle.load(file)
if record['Roll No'] == roll_no:
new_name = input("Enter new name: ")
new_class = input("Enter new class: ")
record['Name'] = new_name
record['Class'] = new_class
modified = True
records.append(record)
except EOFError:
pass
if modified:
with open(filename, 'wb') as file:
for record in records:
pickle.dump(record, file)
print("Record modified.")
else:
print("Record not found.")
def delete_record(filename):
roll_no = int(input("Enter roll number to delete: "))
records = []
deleted = False
try:
with open(filename, 'rb') as file:
while True:
record = pickle.load(file)
if record['Roll No'] != roll_no:
records.append(record)
else:
deleted = True
except EOFError:
pass
if deleted:
with open(filename, 'wb') as file:
for record in records:
pickle.dump(record, file)
print("Record deleted.")
else:
print("Record not found.")
def menu():
filename = "data.dat"
while True:
print("1. Add Record")
print("2. Display All Records")
print("3. Display Specific Record")
print("4. Modify Record")
print("5. Delete Record")
print("6. Exit")
if choice == 1:
add_record(filename)
elif choice == 2:
display_all_records(filename)
elif choice == 3:
display_specific_record(filename)
elif choice == 4:
modify_record(filename)
elif choice == 5:
delete_record(filename)
elif choice == 6:
break
else:
print("Invalid choice.")
menu()
ᯓ Output 15 ᯓ
╰┈➤
⊹ ࣪ ˖Program 16ˊˎ-
ᯓ Output 16 ᯓ
a)
b)
c)
d)
e)
f)
⊹ ࣪ ˖Program 17ˊˎ-
★Write following queries:
a) Write a query to display cube of 5.
b) Write a query to display the number
563.854741 rounding off to the next
hundred.
c) Write a query to display ‘put’ from the
word “Computer”
d) Write a query to display today’s date
into DD.MM.YYYY format.
e) Write a query to display ‘DIA” from the
word “MEDIA”/
f) Write a query to display first 4 digits of
productioncost.
g) Write a query to display the last 4 digits
of release dates.
h) Write a query to display weekday of
release dates.
i) Write a query to display dayname on which
movies are going to be released.
ᯓ Output 17 ᯓ
a)
b)
c)
d)
e)
f)
g)
h)
i)
⊹ ࣪ ˖Program 18ˊˎ-
★
ᯓ Output 18 ᯓ
a)
b)
c)
d)
e)
f)
⊹ ࣪ ˖Program 19ˊˎ-
★Write the following queries:
a) Display the matchid, teamid, teamscore
who scored more than 70 in 1st inning along with
team name.
b) Display matchid, teamname, and
2ndteamscore b/w 100 to 160.
c) Display matchid, teamnames
along w/ matchdates.
d) Display unique team names
e) Display matchid and matchdate
played by Aandhi and Shailab
ᯓ Output 19 ᯓ
a)
b)
c)
d)
e)
⊹ ࣪ ˖Program 20ˊˎ-
★
ᯓ Output 20 ᯓ
a)
b)
c)
d)
e)