LOVELY PUBLIC SR. SEC.
SCHOOL,
NEW LAYAL PUR
PYTHON PROGRAM FILE
PYTHON (083)
Name: Tanvi Kumari
Class: XII E
Roll no. : _____________
CERTIFICAT
E
The is to certify that Tanvi Kumari , student of
class XII-E of LOVELY PUBLIC SR. SEC. SCHOOL,
NEW LAYAL PUR has completed the PRACTICAL
FILE during the year 2025-26 towards fulfillment of
credit for the Computer Science Practical evaluation
of CBSE and submitted satisfactory report, as
compiled in the following pages, under supervision.
……………………….…. ………….………………
Internal Examiner Head Of The
Signature Department Signature
INDEX
S. TABLE OF CONTENTS REMARKS
NO.
1. Write a menu driven function that prints area and perimeter of
circle, square, rectangle, triangle and parallelogram depending upon
user choice.
2. Write a program to print the sum & product of N natural numbers.
3. Write a program to calculate and print the factorial of a number.
4. Write a program to check whether the given number is palindrome
or not.
5. Write a program to print table of numbers.
6. Write a program to print Fibonacci series
7. Write a program to input a number and check whether it is a prime
number or not.
8. Write a program to input a number and check whether it is a
Armstrong number or not.
9. Ques 9. Write a program to find the greatest and smallest of all
numbers from 10 numbers entered by the user.
10. Write a program to input and print their LCM and HCF.
11. Write a program to Find Greatest and Smallest of 10 Numbers.
12. Write a program to count Vowels and Consonants in a String.
13. Write a program to check whether a number is even or odd.
14. Write a program to count digits, letters, and special characters in a
string.
15. Write a program to reverse a number
16. Write a program to check whether the character is vowel or
consonant.
17. Write a program to check if a number is perfect (sum of factors =
number).
18. Write a program to print pattern (triangle of stars).
19. Write a program to count positive, negative & zero numbers from a
list of 10 numbers.
20. Write a program to find the sum of digits of a number.
21. Write a function to read and count words that start with vowel in
[Link]
22. Write a function to display the lines that start with ‘A’ in [Link]
23. Write a function to display the lines that contains with ‘vote’ in
[Link]
24. Write a function to count and display 4 letter words in [Link]
25. Write a function to display the words that end with digit in [Link]
26. Write a function to insert records in binary file [Link]. The
columns are- RollNo, Name, Marks, Stream
27. Write a function to update records in binary file [Link]. The
columns are- RollNo, Name, Marks, Stream.
28. Update name of student whose roll number is fetched from the user.
29. Write a function to read a record from the binary file [Link].
Record contains bookname, author, genre.
30. Write a function to display employee having salary between 25000
and 30000 form file [Link].
31. Write a function to display the records of books whose author is
Ruskin Bond and price is less than 500 from file [Link].
32. Write a function Accept() to create a CSV file [Link].
33. The records should contain: product ID, product names, quantity
sold, price per unit.
34. Write a function to display the data of furniture whose price is
greater than 100000 from file [Link]
35. Write a function to count number of students who have scored an A
grade from [Link] file.
36. Write a function to count number of students who won the match
from CSV file [Link]
37. Write a Python program to delete the student record from the
student table whose Student_ID is 105.
38. After inserting the record, the function should then retrieve and
display all records from the STUDENT where the Marks are greater
than or equal to 80.
39. Write a Python program to update the Marks to 95 and Course to
'Al Basics' for the student whose Student_ID is 305 in the
course_enrollment table.
40. Write a Python function to display all Name and Price details from
the SHOP table of the codm database belonging to a specific
Category entered by the user.
41. Write a Python program to display the names and marks of all
students who scored more than or equal to 85 marks from the
course_enrollment [Link] details
42. Write a program to add, delete and display new package from list of
package description using stack.
43. Write a function to add, delete and show a new score in the list of
scores of a game using stack.
44. Write a function to show push, pop and show operations of stack to
add and remove a book.
Ques 1. Write a menu driven function that prints area and perimeter of circle, square,
rectangle, triangle and parallelogram depending upon user choice.
def circle():
r=int(input(“Enter radius of circle:” ))
per=2*3.14*r
area=3.14*r*r
print ("Perimeter of the circle is=",per,"and area of the circle is, area)
def square():
s=int(input("Enter the side of the square: "))
per=4*s
area=s*s
print("Perimeter of the square is=",per, and area of the square is", area)
def rectangle():
l=int(input("Enter length: "))
b=int(input("Enter breadth: '))
per=2*(1+b)
area=l*b
print("Perimeter of the rectangle is=",per, "and area of the rectangle is", area)
def triangle():
b=int(input("Enter base of the triangle: "))
h=int(input("Enter height of the triangle: "))
I=int(input("Enter third side of triangle: "))
per=l+h+b
area=1/2*b*h
print("Perimeter of the triangle is”, per, and area of the triangle is", area)
def parra():
j=int(input("Enter length: "))
k=int(input("Enter width: "))
w=int(input("Enter height: "))
area=j*k
per=2*/+k*w
print("Perimeter of the parallelogram is",per, and "area of the parallelogram is", area)
while True:
print()
print (“***Main menu***”)
print("1. Area and perimeter of circle")
print (2. Area and perimeter of square")
print("3. Area and perimeter of rectangle")
print ("4. Area and perimeter of triangle")
print (5. Area and perimeter of parallelogram")
print("6. Exit")
print()
ch=int(input("Enter your choice: "))
print()
if ch==1:
circle()
elif ch==2:
square()
elif ch==3:
rectangle()
elif ch==4:
triangle()
elif ch==5:
parra()
elif ch==6:
break
else:
print('invalid choice')
Output:
*** MAIN MENU ***
1. Area and Perimeter of Circle
2. Area and Perimeter of Square
3. Area and Perimeter of Rectangle
4. Area and Perimeter of Triangle
5. Area and Perimeter of Parallelogram
6. Exit
Enter your choice: 1
Enter radius of circle: 7
Perimeter of the circle is = 43.96 and area of the circle is = 153.86
*** MAIN MENU ***
Enter your choice: 2
Enter the side of the square: 5
Perimeter of the square is = 20 and area of the square is = 25
*** MAIN MENU ***
Enter your choice: 3
Enter length: 8
Enter breadth: 4
Perimeter of the rectangle is = 24 and area of the rectangle is = 32
*** MAIN MENU ***
Enter your choice: 5
Enter length: 6
Enter breadth: 3
Enter height: 4
Perimeter of the parallelogram is = 18 and area of the parallelogram is = 24
*** MAIN MENU ***
Enter your choice: 6
Ques 2. Write a program to print the sum & product of N natural numbers.
num = int(input("Enter the number: "))
if num < 0:
print("Enter a positive number")
else:
Sum = 0
pro = 1
while num > 0:
Sum += num
pro *= num
num -= 1
print("The sum is", Sum)
print("The product is", pro)
Output:
Enter the number: 5
The sum is 15
The product is 120
Ques 3. Write a program to calculate and print the factorial of a number.
num = int(input("Enter a number: "))
if num < 0:
print("Factorial does not exist for negative numbers.")
elif num == 0:
Output:
print("The factorial of 0 is 1")
Enter a number: 5
else:
The factorial of 5 is 120
fact = 1
for i in range(1, num + 1):
fact = fact * i
print("The factorial of", num, "is", fact)
Ques 4. Write a program to check whether the given number is palindrome or not.
num = int(input("Enter a number: "))
# Store original number
temp = num
rev = 0
while num > 0:
digit = num % 10
rev = (rev * 10) + digit
num = num // 10
if temp == rev:
print("The number is a Palindrome.")
else:
print("The number is not a Palindrome.")
Output:
Enter a number: 121
The number is a Palindrome.
Ques 5. Write a program to print table of numbers.
Output:
Enter a number: 5
num = int(input("Enter a number: ")) Multiplication Table of 5
print("Multiplication Table of", num) 5 x 1 = 5
5 x 2 = 10
for i in range(1, 11):
5 x 3 = 15
print(num, "x", i, "=", num * i) 5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
Ques 6. Write a program to print Fibonacci series
n = int(input("Enter the number of terms: "))
a, b = 0, 1
count = 0
if n <= 0:
print("Please enter a positive integer")
elif n == 1:
print("Fibonacci sequence up to", n, "term:")
print(a)
else:
print("Fibonacci sequence:")
while count < n:
print(a, end=" ")
c=a+b
a=b
b=c
count += 1
Output:
Enter the number of terms: 7
Fibonacci sequence:
0 1 1 2 3 5 8
Ques 7. Write a program to input a number and check whether it is a prime number or
not.
num = int(input("Enter a number: "))
if num <= 1:
print("The number is not prime.")
else:
for i in range(2, num):
if num % i == 0:
print("The number is not prime.")
break
else:
print("The number is prime.")
Output:
Enter a number: 10
The number is not prime.
Enter a number: 7
The number is prime.
Ques 8. Write a program to input a number and check whether it is a Armstrong number
or not.
num = int(input("Enter a number: "))
# Find the number of digits
order = len(str(num))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num, "is an Armstrong number.")
else:
print(num, "is not an Armstrong number.")
Output:
Enter a number: 153
153 is an Armstrong number.
Enter a number: 123
123 is not an Armstrong number.
Ques 9. Write a program to find the greatest and smallest of all numbers from 10
numbers entered by the user.
numbers = []
print("Enter 10 numbers:")
for i in range(10):
num = int(input("Enter number " + str(i+1) + ": "))
[Link](num)
largest = max(numbers)
smallest = min(numbers)
print("The greatest number is:", largest)
print("The smallest number is:", smallest)
Output:
Enter 10 numbers:
Enter number 1: 12
Enter number 2: 45
Enter number 3: 7
Enter number 4: 89
Enter number 5: 34
Enter number 6: 56
Enter number 7: 2
Enter number 8: 78
Enter number 9: 23
Enter number 10: 67
The greatest number is: 89
The smallest number is: 2
Ques 10. Write a program to input and print their LCM and HCF.
def compute_hcf(x, y):
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
return hcf
def compute_lcm(x, y):
if x > y:
greater = x
else:
greater = y
while True:
if (greater % x == 0) and (greater % y == 0):
lcm = greater
break
greater += 1
return lcm
# Main program
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("The HCF of", num1, "and", num2, "is:", compute_hcf(num1, num2))
print("The LCM of", num1, "and", num2, "is:", compute_lcm(num1, num2))
Output:
Enter first number: 12
Enter second number: 18
The HCF of 12 and 18 is: 6
The LCM of 12 and 18 is: 36
Ques 11. Write a program to Find Greatest and Smallest of 10 Numbers.
nums = []
for i in range(10):
n = int(input("Enter number: "))
[Link](n)
print("Greatest number:", max(nums))
print("Smallest number:", min(nums))
Input:
Output:
Enter number: 45
Enter number: 12 Greatest number: 98
Enter number: 98 Smallest number: 5
Enter number: 5
Ques 12. Write a program to count Vowels and Consonants in a String.
text = input("Enter a string: ").lower()
vowels = 0
consonants = 0
for ch in text:
if ch in "aeiou":
vowels += 1
elif [Link]():
consonants += 1
print("Vowels:", vowels)
print("Consonants:", consonants)
Input: Output:
Enter a string: Computer Science Vowels: 6
Consonants: 10
Ques 13. Write a program to check whether a number is even or odd.
num = int(input("Enter a number: "))
if num % 2 == 0:
print(num, "is Even")
else:
print(num, "is Odd")
Input: Output:
Enter a number: 12 12 is Even
Ques 14. Write a program to count digits, letters, and special characters in a string.
text = input("Enter a string: ")
letters = digits = special = 0
for ch in text:
if [Link]():
letters += 1
elif [Link]():
digits += 1
else:
special += 1
print("Letters:", letters)
print("Digits:", digits)
print("Special characters:", special)
Input: Output:
Enter a string: Hello123@2025! Letters: 5
Digits: 7
Special characters: 2
Ques 15. Write a program to reverse a number
num = int(input("Enter a number: "))
rev = 0
while num > 0:
digit = num % 10
rev = rev * 10 + digit
num //= 10
print("Reversed number is:", rev)
Input: Output:
Enter a number: 54321 Reversed number is: 12345
Ques 16. Write a program to check whether the character is vowel or consonant.
ch = input("Enter a character: ").lower()
if ch in "aeiou":
print(ch, "is a vowel")
else:
print(ch, "is a consonant")
Input: Output:
Enter a character: A a is a vowel
Ques 17. Write a program to check if a number is perfect (sum of factors = number).
num = int(input("Enter a number: "))
s=0
for i in range(1, num):
if num % i == 0:
s += i
if s == num:
print(num, "is a Perfect number")
else:
print(num, "is not a Perfect number")
Input: Output:
Enter a number: 6 6 is a Perfect number
Ques 18. Write a program to print pattern (triangle of stars).
n = int(input("Enter rows: "))
for i in range(1, n+1):
print("*" * i)
Input: Output:
Enter rows: 5 *
**
***
****
*****
Ques 19. Write a program to count positive, negative & zero numbers from a list of 10
numbers.
pos = neg = zero = 0
for i in range(10):
n = int(input("Enter number: "))
if n > 0:
pos += 1
elif n < 0:
neg += 1
else:
zero += 1
print("Positive:", pos)
print("Negative:", neg)
print("Zero:", zero)
Input: Output:
Enter number: 5 Positive: 4
Enter number: -3 Negative: 3
Enter number: 0 Zero: 3
Enter number: 12
Enter number: -9
Enter number: 0
Enter number: 44
Enter number: -1
Enter number: 7
Enter number: 0
Ques 20. Write a program to find the sum of digits of a number.
num = int(input("Enter a number: "))
s=0
while num > 0:
s += num % 10
num //= 10
print("Sum of digits =", s)
Input: Output:
Enter a number: 1234 Sum of digits = 10
Ques 21. Write a function to read and count words that start with vowel in [Link]
def read():
f=open(‘[Link]’,’r’)
data=[Link]()
word=[Link]()
c=0
for i in word:
if i[0] in ‘aeiouAEIOU’:
c=c+1
print(“Number of words starting with vowel:”, c)
[Link]()
read()
Output:
Number of words starting with vowel: 7
Ques 22. Write a function to display the lines that start with ‘A’ in [Link]
def start():
f=open(‘[Link]’,’r’)
data=[Link]()
for i in data:
if i[0] in ‘Aa’:
print(i)
[Link]()
start()
Output:
Lines starting with ‘A’:
A river flows through the town.
An old man lived by the sea.
Ques 23. Write a function to display the lines that contains with ‘vote’ in [Link]
def vote():
f=open(‘[Link]’,’r’)
data=[Link]()
for i in data:
word=[Link]()
for x in word:
if [Link]()==”vote”:
print(i)
[Link]()
vote()
Output:
Lines containing the word ‘vote’:
Everyone must vote for the right candidate.
The vote was conducted peacefully.
Ques 24. Write a function to count and display 4 letter words in [Link]
def words():
f=open(‘[Link]’,’r’) Output:
data=[Link]() Number of 4-letter words: 9
word=[Link]()
c=0
for i in word:
if len(i)==4:
c=c+1
print(“Number of 4 letter words:”, c)
[Link]()
words()
Ques 25. Write a function to display the words that end with digit in [Link]
def digit():
f=open(‘[Link]’,’r’)
data=[Link]()
word=[Link]()
for i in word:
if i.[-1].isdigit(): Output:
c=c+1
apple1
print(i)
data5
[Link]()
digits() plan9
Ques 26. Write a function to insert records in binary file [Link]. The columns are-
RollNo, Name, Marks, Stream
import pickle
def add():
f=open(“[Link]”,’wb’)
L=[]
while True:
Rollno=int(input(“Enter Roll no. :”))
Name= input(“Enter name of Student :”)
Marks= int(input(“Enter Marks:”))
Stream= input(“Enter stream of Student :”)
Rec=[Rollno, Name, Marks, Stream]
[Link](Rec) Output:
[Link](L,f) Records inserted successfully in [Link].
[Link]()
print(“Records inserted successfully in [Link].”)
add()
Ques 27. Write a function to update records in binary file [Link]. The columns are-
RollNo, Name, Marks, Stream.
Update name of student whose roll number is fetched from the user.
import pickle
def change():
f=open(“[Link]”,’rb+’)
data=[Link](f)
found=0
rollno= int(input(“Enter Roll no. to be searched :”))
for r in data:
rno=r[0]
if rno==rollno:
print(“Current name:”,r[1])
r[1]= input(“Enter NEW name of Student :”)
found=1
break
if found==1:
[Link](0)
[Link](data,f)
print(“UPDATED!”)
[Link]()
Output:
Enter Roll no. to be searched: 103
Current name: Riya
Enter NEW name of Student: Riya Sharma
UPDATED!
Ques 28. Write a function to read a record from the binary file [Link]. Record contains
bookname, author, genre.
import pickle
def read():
f=open(“[Link]”,’rb’)
data=[Link](f)
for i in data:
bname=i[0]
author=i[1]
genre=i[2]
print(“Name of book:”, bname, ”Name of author:”, author, ”Genre:”, genre)
[Link]()
read()
Output:
Name of book: Wings of Fire Name of author: A.P.J. Abdul Kalam Genre: Biography
Name of book: Harry Potter Name of author: J.K. Rowling Genre: Fantasy
Ques 29. Write a function to display employee having salary between 25000 and 30000
form file [Link].
The record contains: employee ID, employee name, salary, designation, department.
import pickle
def sal():
f=open("[Link]",'rb')
data=[Link](f)
for i in data:
if i[3]>=25000 and i[3]<=30000:
print(i)
[Link]() Output:
sal() [102, 'Rohan', 28000, 'Analyst', 'Finance']
[109, 'Simran', 26000, 'Clerk', 'Admin']
Ques 30. Write a function to display the records of books whose author is Ruskin Bond
and price is less than 500 from file [Link].
The record contains: customer name, book name, author, price, genre.
import pickle
def details():
f=open("[Link]",'rb')
data=[Link](f)
for i in data:
if i[2]==”Ruskin Bond” and i[3]<500:
print(i)
[Link]()
details()
Output:
['Aditi', 'Blue Umbrella', 'Ruskin Bond', 350, 'Fiction']
['Samar', 'Rusty', 'Ruskin Bond', 450, 'Novel']
Ques 31. Write a function to count number of records in [Link].
import csv
def countrec():
f=open("[Link]",'r')
robj=[Link](f)
c=0
for i in robj:
c=c+1
print("No. of records present in file=",c)
[Link]()
countrec()
Output:
No. of records present in file = 15
Ques 32. Write a function Accept() to create a CSV file [Link].
The records should contain: product ID, product names, quantity sold, price per unit.
import csv
def Accept():
f=open("[Link]",'w', newline=' ')
wobj=[Link](f,delimiter='\t')
L=[]
while True:
P_id=int(input("Enter product id:"))
P_name=input("Enter producr name:")
Q_sold=int(input("Enter quantity sold:"))
Price_per=int(input("Enter price per unit:"))
rec=[P_id, P_name, Q_sold, Price_per]
[Link](rec)
ch=input("Want to add more(Y/N):")
if ch in 'Nn':
break
[Link](L)
[Link]()
print(“Records inserted successfully in [Link].”)
Accept()
Output:
Records entered successfully in [Link].
Ques 33. Write a function to display the data of furniture whose price is greater than
100000 from file [Link]
The record contains: furniture id, brand name, price, furniture type.
import csv
def search():
f=open("[Link]",'r')
robj=[Link](f)
for i in robj:
if i[2]>100000:
print(i)
[Link]()
search()
Output:
['F102', 'Durian', 125000, 'Sofa Set']
['F108', 'Godrej', 135000, 'Dining Table']
Ques 34. Write a function to count number of students who have scored an A grade from
[Link] file.
The record contains: roll number, student name, grade, class.
import csv
def grade():
f=open("[Link]",'r')
robj=[Link](f)
c=0
for i in robj:
if i[3]=='A':
c=c+1
[Link]()
grade() Output:
Number of students who have scored an A grade: 6
Ques 35. Write a function to count number of students who won the match from CSV file
[Link]
The record contains: name, match type, condition(won/lose), age.
import csv
def wonCount():
f=open("[Link]",'r')
robj=[Link](f)
c=0
for i in robj:
if i[3].islower()=='won':
c=c+1
print("No. of students who won=",c)
[Link]()
wonCount()
Output:
No. of students who won = 4
Ques 36. A MySQL database named SchoolDB has a table named student which contains
the following attributes:
Student_ID (Integer)
Student_Name (String)
Class (String)
Age (Integer)
Consider the following details to establish Python-MySQL connectivity:
Username: school admin
Password: school2025
Host: localhost
Write a Python program to delete the student record from the student table whose
Student_ID is 105.
import [Link] as stor
conn = [Link](host "localhost", user="school_admin", password="school2025",
database="SchoolDB")
cursor = [Link]()
[Link]("DELETE FROM student WHERE Student ID 105")
[Link]()
print("Deleted (cursor rowcount) record(s).")
[Link]()
[Link]()
Output:
Deleted 1 record.
Ques 37. Write a Python function to insert a record into the STUDENT table in a MySQL
database named school. The function should accept user inputs for the following fields:
RollNo (Integer)
Name (String)
Class (Integer)
Marks (Integer)
After inserting the record, the function should then retrieve and display all records from
the STUDENT where the Marks are greater than or equal to 80.
Assume the following for Python-Database connectivity:
Username: root
Password: tiger
Database Name: school
import [Link]
def insert_and_display_student():
try:
conn = [Link](host="localhost", user="root", password="tiger",
database="school")
cursor = [Link]()
roll_no = int(input("Enter RollNo: "7)
name = input("Enter Name: ")
class = int(input("Enter Class: "))
marks = int(input("Enter Marks: "))
[Link]("INSERT INTO STUDENT (RollNo, Name, Class, Marks)
VALUES (%s, %s, %s, %s)", (roll_no, name, class, marks))
STUDENT table where Marks >= 80
[Link]('''SELECT * FROM STUDENT WHERE Marks >= 80")
rows = [Link]()
print("Records from STUDENT with Marks>= 80:")
for row in rows:
print(row)
except [Link]. Error as err:
print("Error:", err)
finally:
if cursor:
[Link]() Output:
if conn: (101, 'Riya', 12, 95)
[Link]()
(104, 'Aryan', 11, 88)
Ques 38. A My SQL database named Edu DB has a table course_enrollment with the
following attributes:
Student_ID: Unique ID of the student (Integer)
Name: Student's name (String)
Course: Enrolled course (String)
Marks: Marks obtained (Integer)
Connection details: Username: edu_admin, Password: learn2025, Host: localhost
Write a Python program to update the Marks to 95 and Course to 'Al Basics' for the
student whose Student_ID is 305 in the course_enrollment table.
import [Link] as edu
conn = [Link](host="localhost", user="edu_admin", password="learn2025",
database="EduDB")
cursor = [Link]()
query = "UPDATE course_enrollment SET Marks=95, Course='AI Basics' WHERE
Student_ID=305"
[Link](query)
[Link]()
print("Record updated successfully.") Output:
[Link]() Record updated successfully.
[Link]()
Ques 39. Write a Python function to display all Name and Price details from the SHOP
table of the codm database belonging to a specific Category entered by the user.
The function should display all matching records, if found.
Assume the following for Python-Database connectivity:
Username: root
Password: root
Database Name: codm
import [Link] as shop
def search():
conn = [Link](host="localhost", user="root", password="root", database="codm")
cursor = [Link]()
cat = input("Enter category to be searched: ")
[Link]("SELECT Name, Price FROM SHOP WHERE
Category='{}'".format(cat))
records = [Link]()
if records:
print("Items in category '{}':".format(cat))
for row in records:
print("Name:", row[0], "\tPrice:", row[1])
else:
print("No records found for the given category.")
[Link]()
[Link]()
Output:
Name: Laptop Price: 55000
Name: Earphones Price: 2500
Ques 40. Write a Python program to display the names and marks of all students who
scored more than or equal to 85 marks from the course_enrollment [Link]
details:
Database Name: EduDB
Table Name: course_enrollment
Username: edu_admin
Password: learn2025
Host: localhost
import [Link] as edu
def sel():
conn = [Link](host="localhost", user="edu_admin", password="learn2025",
database="EduDB")
cursor = [Link]()
query = "SELECT Name, Marks FROM course_enrollment WHERE Marks >= 85"
[Link](query)
records = [Link]()
if records:
print("Students scoring 85 and above:")
for row in records:
print("Name:", row[0], "\tMarks:", row[1])
else:
print("No students found with Marks >= 85")
[Link]()
[Link]()
Output:
Name: Arjun Marks: 92
Name: Neha Marks: 89
Name: Kavya Marks: 95
Ques 41. Write a program to add, delete and display new package from list of package
description using stack.
def MakePush(Package):
n = input('Enter package title: ')
[Link](n)
print('PACKAGE ENTERED SUCCESSFULLY')
def MakePop(Package):
if len(Package) == 0:
print('STACK UNDERFLOW')
else:
print('POPPED ELEMENT:', [Link]())
def DISPLAY(Package):
temp = Package[::-1]
for i in temp:
print(i)
Package = []
while True:
print('\nMAIN MENU')
print('1. Add new package')
print('2. Delete package')
print('3. Display list of packages')
print('4. QUIT')
ch = int(input('Enter your choice: '))
if ch == 1:
MakePush(Package)
elif ch == 2:
MakePop(Package)
elif ch == 3:
DISPLAY(Package)
elif ch == 4:
break
else:
print('Invalid choice!')
Output:
MAIN MENU
1. Add new package
2. Delete package
3. Display list of packages
4. QUIT
Enter your choice: 1
Enter package title: BoxA
PACKAGE ENTERED SUCCESSFULLY
MAIN MENU
1. Add new package
2. Delete package
3. Display list of packages
4. QUIT
Enter your choice: 1
Enter package title: BoxB
PACKAGE ENTERED SUCCESSFULLY
MAIN MENU
1. Add new package
2. Delete package
3. Display list of packages
4. QUIT
Enter your choice: 3
BoxB
BoxA
MAIN MENU
1. Add new package
2. Delete package
3. Display list of packages
4. QUIT
Enter your choice: 2
POPPED ELEMENT: BoxB
MAIN MENU
1. Add new package
2. Delete package
3. Display list of packages
4. QUIT
Enter your choice: 3
BoxA
Ques 42. Write a function to add, delete and show a new score in the list of scores of a
game using stack.
def AddScore(GAME):
n = input('Enter new score: ')
[Link](n)
print('SCORE ADDED SUCCESSFULLY')
def DelScore(GAME):
if len(GAME) == 0:
print('STACK UNDERFLOW')
else:
print('POPPED ELEMENT:', [Link]())
def DISPLAY(GAME):
temp = GAME[::-1]
for i in temp:
print(i)
GAME = []
while True:
print('\nMAIN MENU')
print('1. Add new score')
print('2. Delete score')
print('3. Display game scores')
print('4. QUIT')
ch = int(input('Enter your choice: '))
if ch == 1:
AddScore(GAME)
elif ch == 2:
DelScore(GAME)
elif ch == 3:
DISPLAY(GAME)
elif ch == 4:
break
else:
print('Invalid choice!')
Output:
MAIN MENU
1. Add new score
2. Delete score
3. Display game scores
4. QUIT
Enter your choice: 1
Enter new score: 56
SCORE ADDED SUCCESSFULLY
MAIN MENU
1. Add new score
2. Delete score
3. Display game scores
4. QUIT
Enter your choice: 1
Enter new score: 78
SCORE ADDED SUCCESSFULLY
MAIN MENU
1. Add new score
2. Delete score
3. Display game scores
4. QUIT
Enter your choice: 3
78
56
MAIN MENU
1. Add new score
2. Delete score
3. Display game scores
4. QUIT
Enter your choice: 2
POPPED ELEMENT: 78
MAIN MENU
1. Add new score
2. Delete score
3. Display game scores
4. QUIT
Enter your choice: 3
56
Ques 43. Write a function to show push, pop and show operations of stack to add and
remove a book.
L = []
def PUSH(L):
n = len(L) + 1
j = input('Enter book name: ')
k = int(input('Enter book price: '))
[Link]([n, j, k])
print('BOOK ADDED SUCCESSFULLY')
def POP(L):
if len(L) == 0:
print('STACK UNDERFLOW')
else:
print('POPPED BOOK:', [Link]())
def DISPLAY(L):
L = L[::-1]
for i in L:
print(i)
while True:
print('\nMAIN MENU')
print('1. PUSH')
print('2. POP')
print('3. DISPLAY')
print('4. QUIT')
ch = int(input('Enter your choice: '))
if ch == 1:
PUSH(L)
elif ch == 2:
POP(L)
elif ch == 3:
DISPLAY(L)
elif ch == 4:
break
else:
print('Invalid choice!')
Output:
MAIN MENU
1. PUSH
2. POP
3. DISPLAY
4. QUIT
Enter your choice: 1
Enter book name: Champak
Enter book price: 500
BOOK ADDED SUCCESSFULLY
MAIN MENU
1. PUSH
2. POP
3. DISPLAY
4. QUIT
Enter your choice: 1
Enter book name: Harry Potter
Enter book price: 999
BOOK ADDED SUCCESSFULLY
MAIN MENU
1. PUSH
2. POP
3. DISPLAY
4. QUIT
Enter your choice: 3
[2, 'Harry Potter', 999]
[1, 'Champak', 500]
MAIN MENU
1. PUSH
2. POP
3. DISPLAY
4. QUIT
Enter your choice: 2
POPPED BOOK: [2, 'Harry Potter', 999]
MAIN MENU
1. PUSH
2. POP
3. DISPLAY
4. QUIT
Enter your choice: 3
[1, 'Champak', 500]
MAIN MENU
1. PUSH
2. POP
3. DISPLAY
4. QUIT
Enter your choice: 4
Ques 44. Write a function to show push, pop and show operations on list made of numbers
divisible by 5.
Arr = []
n = int(input('Enter the length of list: '))
for i in range(n):
j = int(input('Enter the element: '))
[Link](j)
L = []
def PUSH(L):
for i in Arr:
if i % 5 == 0:
[Link](i)
print('LIST MODIFIED SUCCESSFULLY')
def POP(L):
if len(L) == 0:
print('STACK UNDERFLOW')
else:
print('POPPED ELEMENT:', [Link]())
def DISPLAY(L):
temp = L[::-1]
for i in temp:
print(i)
while True:
print('\nMAIN MENU')
print('1. PUSH')
print('2. POP')
print('3. DISPLAY')
print('4. QUIT')
ch = int(input('Enter your choice: '))
if ch == 1:
PUSH(L)
elif ch == 2:
POP(L)
elif ch == 3:
DISPLAY(L)
elif ch == 4:
break
else:
print('Invalid choice!')
Output:
Enter the length of list: 5
Enter the element: 10
Enter the element: 13
Enter the element: 25
Enter the element: 40
Enter the element: 9
MAIN MENU
1. PUSH
2. POP
3. DISPLAY
4. QUIT
Enter your choice: 1
LIST MODIFIED SUCCESSFULLY
MAIN MENU
1. PUSH
2. POP
3. DISPLAY
4. QUIT
Enter your choice: 3
40
25
10
MAIN MENU
1. PUSH
2. POP
3. DISPLAY
4. QUIT
Enter your choice: 2
POPPED ELEMENT: 40
MAIN MENU
1. PUSH
2. POP
3. DISPLAY
4. QUIT
Enter your choice: 3
25
10
MAIN MENU
1. PUSH
2. POP
3. DISPLAY
4. QUIT
Enter your choice: 4