Rpfile Merged
Rpfile Merged
Session 2024-25
…………………………………………… ………………………………………
INTERNAL EXAMINER EXTERNAL EXAMINER
1. Write a menu driven program to perform mathematical
calculations like Addition, Subtraction, Division, Multiplication
between two integers. The program should continue running
until user gives the choice to quit.
Program-
while True:
print("\nMenu:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Quit")
S=1+x1/2!+x2/3!+…..+xn/(n+1)!
Program-
import math
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
def calculate_series(x, n):
sum = 1
for i in range(1, n + 1):
term = (x ** i) / factorial(i + 1)
sum += term
return sum
#sample use
x = 2
n = 5
result = calculate_series(x, n)
print("The sum of the series is:", result)
Output-
The sum of the series is: 3.7916666666666665
3Write a program to print following pattern:
*
***
*****
*******
Program-
n = 4 # Number of rows
Output-
*
***
*****
*******
4. Write a program which takes the number of people of various age groups as input and
prints a ticket. At the end of the journey, the program states the number of passengers of
different age groups who travelled and the total amount received as collection of fares.
def generate_ticket(age_group, num_passengers):
ticket_price = 0
if age_group == "child":
ticket_price = 100
elif age_group == "adult":
ticket_price = 200
elif age_group == "senior":
ticket_price = 150
else:
print("Invalid age group")
return 0
Output-
# Example usage:
my_list = [15, 23, 55, 42, 85]
modify_list(my_list)
print(my_list)
Output: [1, 0, 1, 0, 1]
6. Write a program that defines a function MinMax(T) which receives a tuple of integers and
returns the maximum and minimum value stored in tuple.
Program-
def min_max(T):
min_val = max_val = T[0]
for num in T:
if num < min_val:
min_val = num
elif num > max_val:
max_val = num
return min_val, max_val
# Example usage:
my_tuple = (10, 5, 20, 15, 8)
min_value, max_value = min_max(my_tuple)
print("Minimum value:", min_value)
print("Maximum value:", max_value)
Output-
Minimum value: 5 Maximum value: 20
7.Write a program with function INDEX_LIST(L), where L is the list of elements passed as
argument to the function. The function returns another list named ‘indexlist’ that stores the
indices of all Non-Zero elements of L. For e.g. if L contains [12,4,0,11,0,56] then after
execution indexlist will have[0,1,3,5]
Program-
def index_list(L):
indexlist = []
for i in range(len(L)):
if L[i] != 0:
indexlist.append(i)
return indexlist
Output-
L = [12, 4, 0, 11, 0, 56] result = index_list(L) print(result) #
Output: [0, 1, 3, 5]
stock = create_stock_list()
print(stock)
Example Output:
def frequency_list():
word_count = {}
with open('MyFile.txt', 'r') as f:
for line in f:
for word in line.split():
word_count[word] = word_count.get(word, 0) + 1
for word, count in word_count.items():
print(f"{word}: {count}")
def max_word_line():
max_words = 0
max_line = ""
with open('MyFile.txt', 'r') as f:
for line in f:
word_count = len(line.split())
if word_count > max_words:
max_words = word_count
max_line = line.strip()
print("Line with maximum words:", max_line)
def main():
while True:
print("\nMenu:")
print("1. Create text file")
print("2. Generate word frequency list")
print("3. Print line with maximum words")
print("4. Quit")
choice = int(input("Enter your choice: "))
if choice == 1:
create_file()
elif choice == 2:
frequency_list()
elif choice == 3:
max_word_line()
elif choice == 4:
break
else:
print("Invalid choice")
main()
Oputput-
Menu:
1. Create text file
2. Generate word frequency list
3. Print line with maximum words
4. Quit
Enter your choice: 2
This: 1
is: 2
a: 2
sample: 1
text: 2
file.: 1
It: 1
contains: 1
multiple: 1
lines: 1
of: 2
Some: 1
words: 1
may: 1
repeat.: 1
Let's: 1
see: 1
how: 1
the: 1
program: 1
works.: 1
Menu:
1. Create text file
2. Generate word frequency list
3. Print line with maximum words
4. Quit
Enter your choice: 3
10. Write a program to remove all the lines that contains character ‘a’ in a file and write
them to another file.
def remove_lines_with_a(myfile, filteredfile):
with open(myfile, 'r') as f_in, open(filteredfile, 'w') as f_out:
for line in f_in:
if 'a' not in line.lower():
f_out.write(line)
# Example usage:
input_filename = 'input.txt'
output_filename = 'output.txt'
remove_lines_with_a(myfile, filteredfile)
Output-
11. Write a program to create a menu driven program using user
import pickle
def create_applicant_file():
with open('applicants.dat', 'wb') as f:
while True:
app_id = input("Enter Applicant ID (or 'q' to quit): ")
if app_id.lower() == 'q':
break
name = input("Enter Name: ")
qualification = input("Enter Qualification: ")
applicant = (app_id, name, qualification)
pickle.dump(applicant, f)
def display_applicants():
with open('applicants.dat', 'rb') as f:
while True:
try:
applicant = pickle.load(f)
print(f"Applicant ID: {applicant[0]}")
print(f"Name: {applicant[1]}")
print(f"Qualification: {applicant[2]}\n")
except EOFError:
break
def search_applicant():
app_id = input("Enter Applicant ID to search: ")
with open('applicants.dat', 'rb') as f:
found = False
while True:
try:
applicant = pickle.load(f)
if applicant[0] == app_id:
print(f"Applicant ID: {applicant[0]}")
print(f"Name: {applicant[1]}")
print(f"Qualification: {applicant[2]}\n")
found = True
break
except EOFError:
break
if not found:
print("Applicant not found.")
def main():
while True:
print("\nMenu:")
print("1. Create Applicant File")
print("2. Display All Applicants")
print("3. Search Applicant")
print("4. Quit")
choice = int(input("Enter your choice: "))
if choice == 1:
create_applicant_file()
elif choice == 2:
display_applicants()
elif choice == 3:
search_applicant()
elif choice == 4:
break
else:
print("Invalid choice")
main()
Output-
Menu:
1. Create Applicant File
2. Display All Applicants
3. Search Applicant
4. Quit
Enter Applicant ID (or 'q' to quit): A123 Enter Name: Raj Enter Qualification:
B.Tech
Enter Applicant ID (or 'q' to quit): B456 Enter Name: Sumit Enter Qualification:
M.Sc.
Menu:
Menu:
Menu:
12. Write a menu driven program to implement stack data structure using list to Push and
Pop Book details(BookID,BTitle,Author,Publisher,Price). The available choices are:
1-PUSH
2-POP
3-PEEK
4-TRAVERSE
5-QUIT
class Stack:
def __init__(self):
self.stack = []
Menu:
1. Push Book
2. Pop Book
3. Peek Book
4. Traverse Stack
5. Quit
Menu:
1. Push Book
2. Pop Book
3. Peek Book
4. Traverse Stack
5. Quit
Stack is empty.
Menu:
1. Push Book
2. Pop Book
3. Peek Book
4. Traverse Stack
5. Quit
Menu:
1. Push Book
2. Pop Book
3. Peek Book
4. Traverse Stack
5. Quit
Menu:
1. Push Book
2. Pop Book
3. Peek Book
4. Traverse Stack
5. Quit
the list NoVowel so that it stores only those words which do not have
any vowel present in it, from the list ALL. Thereafter pop each word
def main():
ALL = []
NoVowel = []
for i in range(10):
word = input("Enter word {}: ".format(i+1))
ALL.append(word)
push_nv(ALL, NoVowel)
print("\nWords without vowels:")
while NoVowel:
word = NoVowel.pop()
print(word)
if __name__ == "__main__":
main()
Output-
Enter word 1: hello
Enter word 2: world
Enter word 3: python
Enter word 4: java
Enter word 5: cpp
Enter word 6: ruby
Enter word 7: swift
Enter word 8: kotlin
Enter word 9: dart
Enter word 10: go
14. Write a program in Python using a user defined function Push(SItem) where SItem is a
dictionary containing the details of stationary items {Sname:Price}.
The function should push the names of those items in the stack who have price greater than
75, also display the count of elements pushed onto the stack
class Stack:
def __init__(self):
self.items = []
Output-
16 Write Python interface program using MySQL to insert rows in table CLUB in database
GAMES
1, 'Kukreja',35,'Karate','1996/03/27',10000,'M';
2, 'Ravina',34,'Karate','1998-01-20',12000,'F';
3, 'Karan',32,'Squash','2000-02-19',20000,'M';
4,'Tarun',33,'Basket Ball','2005-01-01',15000,'M';
5 ,'Zubin',36,'Swimming','1998-02-24',7500,'M')
6 'Ketaki',33,'Swimming','2001-12-23',8000,'F
import mysql.connector
def insert_data(mydb):
mycursor = mydb.cursor()
sql = "INSERT INTO CLUB (CoachID, CoachName, Age, Sports, DateOfApp,
Pay, Sex) VALUES (%s, %s, %s, %s, %s, %s, %s)"
val = [
(1, 'Kukreja', 35, 'Karate', '1996-03-27', 10000, 'M'),
(2, 'Ravina', 34, 'Karate', '1998-01-20', 12000, 'F'),
(3, 'Karan', 32, 'Squash', '2000-02-19', 20000, 'M'),
(4, 'Tarun', 33, 'Basket Ball', '2005-01-01', 15000, 'M'),
(5, 'Zubin', 36, 'Swimming', '1998-02-24', 7500, 'M'),
(6, 'Ketaki', 33, 'Swimming', '2001-12-23', 8000, 'F')
]
mycursor.executemany(sql, val)
mydb.commit()
print(mycursor.rowcount, "record(s) inserted.")
if __name__ == "__main__":
mydb = mysql.connector.connect(
host="your_host",
user="your_user",
password="your_password",
database="GAMES"
)
insert_data(mydb)
mydb.close()
Output-
17 Write Python interface program using MySQL to retrieve details of coaches as per
thesport name input by user from table CLUB in database GAMES
import mysql.connector
def get_coaches_by_sport(mydb, sport):
mycursor = mydb.cursor()
sql = "SELECT * FROM CLUB WHERE Sports = %s"
val = (sport,)
mycursor.execute(sql, val)
result = mycursor.fetchall()
if result:
for row in result:
print(f"Coach ID: {row[0]}")
print(f"Coach Name: {row[1]}")
print(f"Age: {row[2]}")
print(f"Sport: {row[3]}")
print(f"Date of Application: {row[4]}")
print(f"Pay: {row[5]}")
print(f"Sex: {row[6]}\n")
else:
print("No coaches found for the specified sport.")
if __name__ == "__main__":
mydb = mysql.connector.connect(
host="your_host",
user="your_user",
password="your_password",
database="GAMES"
)
sport = input("Enter the sport name: ")
get_coaches_by_sport(mydb, sport)
mydb.close()
Output-
Enter the sport name: Karate
Coach ID: 1
Coach Name: Kukreja
Age: 35
Sport: Karate
Date of Application: 1996-03-27
Pay: 10000.00
Sex: M
Coach ID: 2
Coach Name: Ravina
Age: 34
Sport: Karate
Date of Application: 1998-01-20
Pay: 12000.00
Sex: F
Output-
Query i:
Export to Sheets
Query ii:
Export to Sheets
Query iii:
| Sports |
|---|---|
| Karate |
| Swimming |
Query iv:
| COUNT(DISTINCT Sports) |
|---|---|
|4 |
Query v:
19 . Write Python interface program using MySQL to increase price by 10% in table
CUSTOMER of MYORG database
import mysql.connector
def increase_price(mydb):
mycursor = mydb.cursor()
sql = "UPDATE CUSTOMER SET Price = Price * 1.10"
mycursor.execute(sql)
mydb.commit()
print(mycursor.rowcount, "record(s) updated.")
if __name__ == "__main__":
mydb = mysql.connector.connect(
host="your_host",
user="your_user",
password="your_password",
database="MYORG"
)
increase_price(mydb)
mydb.close()
20. Write a Python interface program using MySQL to delete all those customers whose
name contains Kumar from table CUSTOMER in database MYORG.
import mysql.connector
def delete_customers_with_kumar(mydb):
mycursor = mydb.cursor()
sql = "DELETE FROM CUSTOMER WHERE CustomerName LIKE '%Kumar%'"
mycursor.execute(sql)
mydb.commit()
print(mycursor.rowcount, "record(s) deleted.")
if __name__ == "__main__":
mydb = mysql.connector.connect(
host="your_host",
user="your_user",
password="your_password",
database="MYORG"
)
delete_customers_with_kumar(mydb)
mydb.close()
21.. Create following tables in database MYORG with appropriate data type using SQL commands of
following structure.
Table : Company Table Customer
CID Primary key CustId Primary Key
Name Not Null Name Not Null
City Not Null Price Not Null
Product Name Not Null Qty Check greater than 0
CID Foreign Key
22. Write SQL commands to insert following data in above created tables Company and Customer ,
also list all data .
Table: Company
CID Name City ProductName
111 Sony Delhi TV
222 Nokia Mumbai Mobile
333 Onida Delhi TV
444 Blackberry Mumbai Mobile
555 Samsung Chennai Mobile
666 Dell Delhi Laptop
Table:Customer
CustId Name Price Qty CID
101 Rohan Sharma 70000 20 222
102 Deepak Kumar 50000 10 666
103 Mohan Kumar 30000 5 111
104 Sahil Bansal 35000 3 333
105 Neha Soni 25000 7 444
106 Sonal Agarwal 20000 5 333
107 Arjun Singh 50000 15 666
Program-
Q23 Write SQL commands for the following queries based on tables Company and Customer.
Display those company names having price less than 30000.
To increase price by 1000 for those customers whose name starts with ‘S’.
To display Company details in reverse alphabetical order.
To display customer details along with product name and company name of the product.
To display details of companies based in Mumbai or Delhi.
Output-
+-----+-----------+---------+------------+
| CID | Name | City | ProductName|
+-----+-----------+---------+------------+
| 111 | Sony | Delhi | TV |
| 222 | Nokia | Mumbai | Mobile |
| 333 | Onida | Delhi | TV |
| 444 | Blackberry| Mumbai | Mobile |
| 555 | Samsung | Chennai | Mobile |
| 666 | Dell | Delhi | Laptop |
+-----+-----------+---------+------------+
+--------+-----------------+--------+-----+-----+
| CustId | Name | Price | Qty | CID |
+--------+-----------------+--------+-----+-----+
| 101 | Rohan Sharma | 70000 | 20 | 222 |
| 102 | Deepak Kumar | 50000 | 10 | 666 |
| 103 | Mohan Kumar | 30000 | 5 | 111 |
| 104 | Sahil Bansal | 35000 | 3 | 333 |
| 105 | Neha Soni | 25000 | 7 | 444 |
| 106 | Sonal Agarwal | 20000 | 5 | 333 |
| 107 | Arjun Singh | 50000 | 15 | 666 |
+--------+-----------------+--------+-----+-----+
Bibliography
For successfully completing my project file. I have taken
help from the following
1. Python
2. Mysql
3. VScode
4. https://www.geeksforgeeks.org/
5.