Practical (1) Merged
Practical (1) Merged
1
Date:2/3/25
                                         SOURCE CODE
def GetStory():
  with open('Story.txt','w') as f:
     while True:
       line = input("Enter a line:")
       f.write(line+'\n')
       Choice = input("More?(Y/N)")
       if Choice in 'nN':
          break
def ViewStory():
  try:
     with open("Story.txt", "r") as f:
        data = f.read()
        print(data)
  except
     FileNotFoundError:
     print("File not found")
def Words():
  with open ("Story.txt","r") as f:
     data = f.read().split()
     for K in data:
        print(K)
def menu():
  while
  True:
     print("1. Create Story")
     print("2. View Story")
     print("3. Display
     Words") print("4. Exit")
     choice = input("Enter your choice (1-4): ")
     if choice == '1':
        GetStory()
     elif choice == '2':
        ViewStory()
     elif choice == '3':
   Words()
elif choice == '4':
   print("Exiting")
   break
else:
   print("Invalid choice")
OUTPUT
  Enter choice: 1
  This is my story.
  It has two lines.
  Enter choice: 2
  This is my story.
  It has two lines.
  Enter choice: 3
  This
  is
  my
  story
  . It
  has
  two
  lines.
                                       PROGRAM NO.2
Date: 5/3/25
                                       SOURCE CODE
def Createnotes():
  with open('Notes.txt','w') as f:
     while True:
       line = input("Enter notes:")
       f.write(line+'\n')
       Choice = input("More?(Y/N)")
       if Choice in 'nN':
          break
def CountAVD():
  with open("Notes.txt", "r") as f:
     alphabets = vowels = digits = 0
     data = f.read().split()
     for K in data:
        for A in K:
           if A.isalpha():
              alphabets += 1
              if A in "AEIOUaeiou":
                 vowels += 1
           elif
              A.isdigit():
              digits += 1
     print("Alphabets:",alphabets)
     print("Vowels:",vowels)
     print("Digits:",digits)
def
  Shownotes():
  try:
     with open("Notes.txt", "r") as
        f: data = f.read()
        print(data)
  except
     FileNotFoundError:
     print("File not found")
def Revtext():
with open("Notes.txt", "r") as f:
     data = f.readlines()
     for K in data:
        if K[0]=="T":
           print(K[::-1])
def menu2():
  while True:
     print("1. Create Notes")
     print("2. Count Alphabets,
     Vowels, Digits") print("3. Show
     Notes") print("4. Reverse 'T'
     Lines") print("5. Exit")
     choice = input("Enter your choice (1-5): ")
     if choice == '1':
        Createnotes()
     elif choice == '2':
        CountAVD()
     elif choice == '3':
        Shownotes()
     elif choice == '4':
        Revtext()
     elif choice == '5':
        print("Exiting")
        break
     else:
        print("Invalid choice")
OUTPUT
       Enter choice: 1
       Enter lines (type 'END' to
       stop): This is Test.
       That is fine.
       Enter choice: 2
       Alphabets: 20
       Vowels: 7
       Digits: 0
       Enter choice: 3
       This is Test.
       That is fine.
       Enter choice: 4
       .tseT si sihT
       .enif si tahT
                                     PROGRAM NO.3
Date: 9/3/25
Create a text file “story.txt” and then and then find and display the number of vowels,
consonants, uppercase, lowercase characters in the text file
                                     SOURCE CODE
def Create():
  with open('Story.txt','w') as f:
     while True:
       line = input("Enter a line:")
       f.write(line+'\n')
       Choice = input("More?(Y/N)")
       if Choice in 'nN':
          break
def
  Count():
  try:
     vowels = consonants = uppercase = lowercase =
     0 with open("story.txt", "r") as f:
        for K in f:
           for A
           in K:
              if
                 A.isalpha()
                 : if A in
                     'AEIOUaeiou':
                     vowels += 1
                 else:
                     consonants += 1
                 if A.isupper():
                     uppercase += 1
                 elif A.islower():
                     lowercase += 1
     print("Vowels:", vowels)
     print("Consonants:", consonants)
     print("Uppercase letters:", uppercase)
     print("Lowercase letters:", lowercase)
  except
     FileNotFoundError:
     print("File not found")
                                               OUTPUT
        Vowels: 10
        Consonants: 15
        Uppercase: 2
        Lowercase: 23
                                      PROGRAM NO.4
Date: 12/3/25
                                       SOURCE CODE
def fun1(X,N):
  Total = 0
  for K in range (1,N+1):
     Total = Total + (X**K)
  print(Total)
def fun2(N,U):
  Total = 0
  for K in range(1,N+1):
     F=1
     for A in range(1,K+1):
        F=F*A
     Total = Total + ((U**K)/F)
  print(Total)
def fun3(X,N):
  Total = 0
  for K in range(1,N+1):
     Total += (K*X)
      def
 fun4(N,U):
  Total = 1
  Sign = -1
  for K in range(2,N+1):
    F=1
     for A in range(1,K+1):
        F*=A
     Total += (F/(U**K))*(Sign**(K-
  1)) print(Total)
                         OUTPUT
                                     SOURCE CODE
L=[]
def
  Addvalues():
  while True:
     Value= int(input("Enter value:"))
     L.append(Value)
     Choice = input("More?(Y/N)")
     if Choice in 'Nn':
        break
def Dispvalues():
  print("Values:",L)
def SwapPair(L):
for k in range(0,len(L)-1,2):
L[k],L[k+1]=L[k+1],L[k]
def SwapHalf(L):
  N = len(L)
  if N%2==0:
     for k in range(0,N//2,1): L[k],L[N//2+k]=L[N//2+k],L[k]
  else:
     for k in range(0,N//2,1): L[k],L[N//2+k+1]=L[N//2+k+1],L[k]
                                             OUTPUT
        Enter an integer :
        1 More [Y/N] ? Y
        Enter an integer :
        2 More [Y/N] ? Y
        Enter an integer :
        3 More [Y/N] ? N
        List is : [1, 2, 3]
        List is : [2, 1, 3]
        List is : [3, 1, 2]
                                     PROGRAM NO.6
Date: 22/3/25
SOURCE CODE
def Factorial(n):
  F=1
  for K in range(1,n+1):
     F=F*K
  print(F)
def Reverse(n):
  print(str(n)[::-1])
def
  Isprime(n):
  if n==1:
     print(n,"is neither prime nor composite")
  elif n>1:
     for K in range(2,n):
        if n%K==0:
           print(n,"is
           composite") break
     else:
        print(n,"is prime")
def menu3():
   n=int(input("Enter
   no.:")) while True:
      print('''1. Factorial
2. Reverse
3. Is it prime?
4. Exit''')
      choice = input("Enter your choice (1-4): ")
     if choice == '1':
        Factorial(n)
     elif choice == '2':
        Reverse(n)
     elif choice == '3':
        Isprime(n)
     elif choice == '4':
        print("Exiting")
       break
    else:
       print("Invalid
choice") menu3()
OUTPUT
      Enter choice: 1
      Factorial: 120
      Enter choice: 2
      Reverse: 321
      Enter choice: 3
      Prime
                                   PROGRAM NO.7
Date: 27/3/25
   Write a Python code with the following functions performing mentioned operations on a
   binary file “CANDIDATE.DAT” containing lists with [Candidateno of type int, Cname of
   type string, Score of type float]
       a) Enrol( ), to add details of new CANDIDATEs from the user and save
           in “CANDIDATE.DAT”.
       b) ShowAll( ), to display the entire content of “CANDIDATE.DAT”
       c) GetPass( ), to read content from “CANDIDATE.DAT” and display details of
           those candidates whose Score is>=50
       d)     AverageScore( ), to find and return the average of Score from
“CANDIDATE.DAT” Write menu driven code to call the above functions.
                                    SOURCE CODE
import
pickle
def
Enrol():
   with open("CANDIDATE.DAT","wb") as
     f: L = []
     while True:
        Canno = int(input("Enter candidate number:"))
        Cname = input("Enter name:")
        Score = float(input("Enter Score:"))
        L.append([Canno,Cname,Score])
        Choice = input("More?(y/n):")
        if Choice in 'nN':
           break
     pickle.dump(L,f)
def Showall():
  with open("CANDIDATE.DAT","rb") as f:
     data = pickle.load(f)
     print("Candidate no.","Candidate Name","Score",sep="\t")
     for K in data:
        print(K[0],K[1],K[2],sep="\t \t")
def Getpass():
  with open("CANDIDATE.DAT","rb") as f:
     data = pickle.load(f)
     for K in data:
        if
        K[2]>=50:
           print("Candidate no.","Candidate Name","Score",sep="\t")
           print(K[0],K[1],K[2],sep="\t \t")
        else:
           print("no record found")
def AverageScore():
  with open("CANDIDATE.DAT","rb") as f:
    data = pickle.load(f)
    S = 0;N=0
    for K in data: S
       = S + K[2]
       N +=1
    print("Average score = ", S/N)
def menu4():
   while True:
     print('''1. Add detail
2. Display Content
3. Display Content of candidates whose score is more than 50
4. Average score
5. Exit''')
     choice = input("Enter your choice (1-4): ")
    if choice == '1':
       Enrol()
    elif choice == '2':
       Showall()
    elif choice == '3':
       Getpass()
     elif choice == '4':
        AverageScore()
     elif choice == '5':
       print("Exiting")
       break
    else:
       print("Invalid
choice") menu4()
OUTPUT
       CandidateNo:
       101 Name: Asha
       Score: 67.5
       All Candidates:
       [101, 'Asha', 67.5]
       Passed
       Candidates: [101,
       'Asha', 67.5]
                                    SOURCE CODE
import pickle
def Register():
  L=[]
  with open("ACCOUNTS.DAT", "wb") as f:
     while True:
        Ano = int(input("Enter Account Number: "))
        Name = input("Enter Name: ")
        Balance = float(input("Enter Balance (min Rs.500): "))
        L.append([Ano, Name, Balance])
        Choice =
        input("More?(y/n):") if
        Choice in 'nN':
           break
     if Balance >= 500:
           pickle.dump(L, f)
           print("Account
           Registered")
     else:
        print("Minimum Rs.500 required. Account not registered.\n")
def Displayall():
  with open("ACCOUNTS.DAT","rb") as f:
     data = pickle.load(f)
     print("Account no.","Name "," Score",sep="\t")
     for K in data:
        print(K[0],K[1],K[2],sep="\t \t")
def Transact():
  with open("ACCOUNTS.DAT","rb+") as f:
     data = pickle.load(f)
     Acno = int(input("Enter account no.:"))
     print('1. Withdraw\n2. Deposit')
     Choice = int(input("What do you want to do?(1 or 2):"))
     if Choice == 1:
        for K in data:
           if K[0] == Acno:
              Amount = int(input("How much money do you want to withdraw?:"))
              K[2] = K[2] - Amount
              print("New amount =", K[2])
           else:
              print("Account no. not found")
        f.seek(0)
        pickle.dump(data,f)
     elif Choice == 2:
        for K in data:
           if K[0] == Acno:
              Amount = int(input("How much money do you want to Deposit?:"))
              K[2] = K[2] + Amount
              print("New amount =", K[2])
           else:
              print("Account no. not found")
        f.seek(0)
        pickle.dump(data,f)
def BankBalance():
  with open("ACCOUNTS.DAT","rb") as f:
     data = pickle.load(f)
     Sum = 0
     for K in data:
        Sum = Sum + K[2]
     print(Sum)
def menu5():
   while True:
     print('''1. Register
2. Display
3. Transact
4. Bank Balance
5. Exit''')
     choice = input("Enter your choice (1-4): ")
    if choice == '1':
       Register()
    elif choice == '2':
       Displayall()
    elif choice == '3':
       Transact()
    elif choice == '4':
       BankBalance()
    elif choice == '5':
       print("Exiting")
       break
    else:
       print("Invalid
choice") menu5()
OUTPUT
      Enter details:
      101 Rahul 6000
      All Accounts:
      [101, 'Rahul',
      6000]
      Transaction: Deposit
      Amount: 1000
      Updated Balance: 7000
      Total Balance: 7000
                                   PROGRAM NO.9
Date: 2/4/25
                                   SOURCE CODE
import
pickle
def
Create():
   with open("EMPLOYEE.DAT","wb") as f:
     L = []
     while True:
        EMPNO = int(input("Enter employee number:"))
        Name = input("Enter Name:")
        Salary = float(input("Enter Salary:"))
        L.append([EMPNO,Name,Salary])
        Choice = input("More?(y/n):")
        if Choice in 'nN':
           break
     pickle.dump(L,f)
def Display():
  with open("EMPLOYEE.DAT","rb") as f:
     data = pickle.load(f)
     print("Employee no.","Employee name","Salary",sep="\
     t") for K in data:
        print(K[0],K[1],K[2],sep="\t \t")
def Search():
  with open("EMPLOYEE.DAT","rb") as f:
     data = pickle.load(f)
     Eno=int(input("Enter employee
     number:")) for K in data:
       if K[0]==Eno:
          print("Employee no.","Employee name","Salary",sep="\t")
          print(K[0],K[1],K[2],sep="\t \t")
break
     else:
def
  Modify(emp):
  L = []
  with open("EMPLOYEE.DAT", "rb") as f:
    while True:
       K = pickle.load(f)
       if K[0] == emp:
          NAME = input("Enter new Name: ")
          SALARY = input("Enter new Salary: ")
          L.append([K[0], NAME, SALARY])
       else:
          L.append(K)
def Delete():
  with open("EMPLOYEE.DAT","rb+") as f:
     data = pickle.load(f)
     L=[]
     Name= input("Enter name:")
     Found = 0
     for K in
     data:
        if K[1] == Name:
           print('Empno:',K[0],"Salary:",K[2])
           Found = 1
        else:
           L.append(K)
     if Found == 0:
        print("No such employee exist")
  with open("EMPLOYEE.DAT","wb") as f:
     pickle.dump(L,f)
def menu6():
   while True:
     print('''1. Create
2. Display
3. Search
4. Modify
5. Delete
6. Exit''')
     choice = input("Enter your choice (1-6): ")
     if choice == '1':
Create()
OUTPUT
All Employees:
Search Result:
After Modify:
After Deletion:
                                        SOURCE CODE
import csv
def Add():
   L=[]
  with open("MEMBER.CSV","a",newline="") as f:
     data = csv.writer(f,delimiter=',')
     while True:
        Mno = int(input("Enter Member number:"))
        Name = input("Enter name:")
        Fee = int(input("Enter fee:"))
        Type = input("Enter type:")
        L.append([Mno,Name,Fee,Type])
        Choice = input("More?(y/n)")
        if Choice in 'nN':
           break
     data.writerows(L)
def DisplayMembers():
  with open("MEMBER.CSV", "r") as f:
     data = csv.reader(f) print("Mno\
     tName\tFee\tType")
     for K in data:
        print(K[0], "\t", K[1], "\t", K[2], "\t", K[3])
def SearchMember():
  mno = input("Enter Member number: ")
  found = 0
  with open("MEMBER.CSV", "r") as f:
     data = csv.reader(f)
     for K in data:
        if K[0] == mno: print("Mno\tName\tFee\
           tType") print(K[0], "\t", K[1], "\t", K[2],
           "\t", K[3])
           found = 1
           break
  if found==0:
     print("No such member.")
def AverageFee():
  total = 0
  count = 0
  with open("MEMBER.CSV", "r") as f:
     data = csv.reader(f)
     for K in data:
        total += int(K[2])
        count += 1
  if count > 0:
     print("Average Fee:", total / count)
  else:
     print("No data")
def menu7():
   while True:
     print('''1. Add detail
2. Display detail
3. Search detail
4. Average fees
5. Exit''')
     choice = input("Enter your choice (1-5): ")
     if choice == '1':
        Add()
     elif choice == '2':
        DisplayMembers()
     elif choice == '3':
        SearchMember()
     elif choice == '4':
        AverageFee
     elif choice == '5':
        print("Exiting")
        break
     else:
        print("Invalid
choice")
                                OUTPUT
SOURCE CODE
def AddItem():
  with open("STOCK.CSV", "a", newline='') as f:
     data = csv.writer(f)
     while True:
       ino = input("Enter Item Number: ")
       item = input("Enter Item Name: ")
       price = float(input("Enter Price: "))
       qty = int(input("Enter Quantity: "))
       data.writerow([ino, item, price, qty])
       choice = input("Add more? (y/n): ")
       if choice in 'nN':
          break
  print("Items
  added")
def DisplayItems():
  with open("STOCK.CSV", "r") as f:
     data = csv.reader(f)
     print("INO", "ITEM", "PRICE", "QTY", "STOCK VALUE", sep='\t')
     for K in data:
        stock = float(K[2]) * int(K[3])
        print(K[0], K[1], K[2], K[3], stock, sep='\t')
def SearchItem():
  ino = input("Enter Item number: ")
  found = 0
  with open("STOCK.CSV", "r") as f:
     data = csv.reader(f)
     for K in data:
        if K[0] == ino:
          print("INO", "ITEM", "PRICE", "QTY", sep='\t')
          print(K[0], K[1], K[2], K[3], sep='\t')
          found = 1
  if found==0:
     print("No such item found")
def DisplayPItems():
  print("Items starting with
  'P':")
  with open("STOCK.CSV", "r") as f:
     data = csv.reader(f)
     for K in data:
         if K[1].startswith("P") or K[1].startswith("p"):
            print(K[1])
def Reorder():
  with open("STOCK.CSV", "r") as f:
     data = csv.reader(f)
     L = []
     for K in data:
        if int(K[3]) < 10:
           L.append(K)
def menu8():
  while True:
  print("1. Add Item")
  print("2. Display Items with Stock Value")
  print("3. Search")
  print("4. Items Starting with 'P'")
  print("5. Reorder")
  print("6. Exit")
  Choice = input("Enter your choice (1-6): ")
  if Choice == '1':
     AddItem()
       elif Choice ==
                   '2':
       DisplayItems()
       elif Choice ==
                   '3':
      SearchItem()
  elif Choice ==
  '4':
   DisplayPItems()
elif Choice == '5':
   Reorder()
elif Choice == '6':
   break
else:
   print("Invalid choice.")
OUTPUT
     REORDER:
     [103, 'Pencil', 10, 9]
                                  PROGRAM NO.12
Date: 10/4/25
SOURCE CODE
import csv
def AddCadets():
  with open("CADETS.CSV", "a", newline='') as f:
     data = csv.writer(f)
     while True:
       CNO = input("Enter Cadet No: ")
       NAME = input("Enter Name: ")
       GENDER = input("Enter Gender (M/F): ")
       AGE = input("Enter Age: ")
       HEIGHT = input("Enter Height: ")
       data.writerow([CNO, NAME, GENDER, AGE, HEIGHT])
       choice = input("more? (y/n): ")
       if choice in 'nN':
          break
def DisplayAll():
  with open("CADETS.CSV", "r") as f:
     data = csv.reader(f)
     print("CNO", "NAME", "GENDER", "AGE", "HEIGHT", sep='\t')
     for K in data:
        print(K[0], K[1], K[2], K[3], K[4], sep='\t')
def DisplayByGender(G):
  with open("CADETS.CSV", "r") as f:
     data = csv.reader(f)
     print("CNO", "NAME", "GENDER", "AGE", "HEIGHT", sep='\t')
     for K in data:
        if K[2].upper() == G.upper():
           print(K[0], K[1], K[2], K[3], K[4], sep='\t')
def ModifyCadet():
  Cno = input("Enter Cno: ")
  L = []
  found = 0
  with open("CADETS.CSV", "r") as f:
     data = csv.reader(f)
     for K in data:
        if K[0] == Cno:
           AGE = input("Enter new Age: ")
           HEIGHT = input("Enter new Height: ")
           L.append([K[0], K[1], K[2], AGE, HEIGHT])
           found = 1
        else:
           L.append(K)
  with open("CADETS.CSV", "w", newline='') as f:
     data = csv.writer(f)
     data.writerows(L)
  if found==1:
     print("Cadet record updated.")
  else:
     print("Cadet not found.")
def menu9():
  while True:
     print("1. Add")
     print("2. Display All")
     print("3. Display by gender")
     print("4. Modify Age & Height")
     print("5. Exit")
     choice = input("Enter your choice (1-5): ")
    if choice == '1':
       AddCadets()
    elif choice == '2':
       DisplayAll()
    elif choice == '3':
       G = input("Enter Gender(M/F) ")
       DisplayByGender(G)
    elif choice == '4':
       ModifyCadet()
    elif choice == '5':
       print("Exiting")
       break
    else:
       print("Invalid choice")
                             OUTPUT
Cadets:
[101, 'Anu', 'F', 18, 5.4]
Gender: F
[101, 'Anu', 'F', 18, 5.4]
After Modify:
[101, 'Anu', 'F', 19, 5.5]
                                        PROGRAM NO.13
Date: 13/4/25
Write a Python code with the following functions performing mentioned operations on a CSV
file “ACCOUNTS.CSV” containing lists with [Ano of type int, Name of type string, Balance of
type float]
  a. Register(), to add details of new account holders as entered by the user in the CSV
     file named ACCOUNTS.CSV.
  b. DisplayAll( ) to display the details of all Account Holders from ACCOUNTS.CSV
SOURCE CODE
import csv
def Register():
  with open("ACCOUNTS.CSV", "a", newline="") as f:
     data = csv.writer(f)
     while True:
       Ano = int(input("Enter Account Number: "))
       Name = input("Enter Name: ")
       Balance = float(input("Enter Balance: "))
       data.writerow([Ano, Name, Balance])
       choice = input("More?(y/n): ")
       if choice in 'nN':
          break
def DisplayAll():
  print("Ano", "Name", "Balance", sep='\t')
  with open("ACCOUNTS.CSV", "r", newline="") as f:
     data = csv.reader(f)
     for K in data:
        print(K[0], K[1], K[2], sep='\t')
def
  menu10():
  while True:
    print("1.
    Register")
    print("2. Display")
    print("3. Exit")
    choice = input("Enter your choice: ")
     if choice == '1':
        Register()
     elif choice == '2':
        DisplayAll()
     elif choice == '3':
        break
     else:
print("Invalid choice")
OUTPUT
You have a stack named BooksStack that contains records of books. Each book record is
represented as a list containing book_title, author_name, and publication_year.
Write the following user-defined functions in Python to perform the specified operations
on the stack BooksStack:
(a)     push_book(BooksStack, new_book): This function takes the stack
BooksStack and a new book record new_book as arguments and pushes the
new book record onto the stack.
(b)     pop_book(BooksStack): This function pops the topmost book record
from the stack and returns it. If the stack is already empty, the function
should display "Underflow".
(c)     peep(BookStack): This function displays the topmost element of the
stack without deleting it. If the stack is empty, the function should display
'None'.
Write menu driven code to call the above functions.
                                 SOURCE CODE
def push_book(BooksStack, new_ book):
   BooksStack.append(new_book)
def pop_book(BooksStack): if
    len(BooksStack) == 0:
      print("Underflow")
   else:
       return BooksStack.pop()
def peep(BooksStack):
  if len(BooksStack) == 0:
      print("None")
  else:
      print("Top Book:", BooksStack[-
1]) BooksStack = []
while True:
  print("\n1. Push Book")
  print("2. Pop Book")
  print("3. Peep Book")
  print("4. Exit")
  choice = input("Enter your choice: ")
  if choice == '1':
      title = input("Enter Book Title: ") author
      = input("Enter Author Name: ")
      year = input("Enter Publication Year: ") new_book =
      [title, author, year] push_book(BooksStack,
      new_book)
  else:
     print("Invalid choice")
OUTPUT
Given a Dictionary Stu_dict containing marks of students for three test-series in the form
Stu_ID:(TS1, TS2, TS3) as key-value pairs.
Write a Python program with the following user-defined functions to perform the
specified operations on a stack named Stu_Stk
(i)     Push_elements(Stu_Stk, Stu_dict) : It allows pushing IDs of
those students, from the dictionary Stu_dict into the stack Stu_Stk, who
have scored more than or equal to 80 marks in the TS3 Test.
(ii)    Pop_elements(Stu_Stk): It removes all elements present inside
the stack in LIFO order and print them. Also, the function displays
'Stack Empty' when there are no elements in the stack.
(iii)   Display(Stu_Stk) : It displays all the elements of stack
Stu_Stk. Write menu driven code to call the above functions.
SOURCE CODE
def Pop_elements(Stu_Stk): if
   not Stu_Stk:
     print("Stack
   Empty") else:
     while Stu_Stk:
        print("Pop:", Stu_Stk.pop())
def
   Display(Stu_Stk):
   if not Stu_Stk:
      print("Stack
   Empty") else:
      print("Stack Elements:", Stu_Stk)
Stu_dict = {
   101: (75, 88, 82),
   102: (90, 78, 79),
   103: (85, 89, 91),
   104: (60, 72, 84),
   105: (78, 80, 76)}
Stu_Stk = []
while True:
   print("\n1. Push Elements")
   print("2. Pop Elements")
   print("3. Display Stack")
   print("4. Exit")
  ch = input("Enter your choice: ")
  if ch == '1':
      Push_elements(Stu_Stk,
  Stu_dict) elif ch == '2':
      Pop_elements(Stu_Stk)
  elif ch == '3':
      Display(Stu_Stk)
  elif ch == '4':
      break
  else:
      print("Invalid choice")
OUTPUT
DATE: 19/4/25
A list, NList contains the following record as list elements: [City, Country, distance from
Delhi] Each of these records are nested together to form a nested list.
Write the following user defined functions in Python to perform the specified operations
on the stack named travel.
(i)     Push_element(NList): It takes the nested list as an argument and
pushes a list object containing the name of the city and country, which
are not in India and distance is less than 3500 km from Delhi.
(ii)    Pop_element( ): It pops the objects from the stack and displays them.
Also, the function should display “Stack Empty” when there are no elements
in the stack.
(iii)   Display( ) : It displays all the elements of stack
travel. Write menu driven code to call the above functions.
SOURCE CODE
def Pop_element(): if
   not travel:
     print("Stack
   Empty") else:
     while travel:
         print("Pop:",
travel.pop()) def Display():
  if not travel:
      print("Stack
      Empty")
  else:
      print("Stack Elements:", travel)
NList = [
   ["Kathmandu", "Nepal", 1000],
   ["Colombo", "Sri Lanka", 3400],
   ["Paris", "France", 7000],
   ["Dhaka", "Bangladesh", 1500],
   ["Mumbai", "India", 1400],
   ["Dubai", "UAE", 2800]]
travel = []
while
True:
  print("\n1. Push Element")
  print("2. Pop Element") print("3.
  Display Stack") print("4. Exit")
  ch = input("Enter your choice: ")
  if ch == '1':
      Push_element(NList)
  elif ch == '2':
      Pop_element()
  elif ch == '3':
      Display()
  elif ch == '4':
      break
  else:
      print("Invalid choice")
OUTPUT
DATE: 4/5/25
SOURCE CODE
import
mysql.connector
def connect():
  return mysql.connector.connect(
     host="localhost",
     user="root",
     password="SgsWrite",
     database="SCHOOL")
def
  displaystudents():
  try:
     con = connect_db()
     cursor = con.cursor()
     query = "select * from student where fee> 5000"
     cursor.execute(query)
     records cursor.fetchall()
     print("Students with Fee > 5000:")
     for row in records:
        print(f"RNO: {row[0]}, NAME: {row[1]}, DOB: {row[2]}, FEE: {row[3]}")
     cursor.close()
     con.close()
  except Exception as e:
     print("Error:", e)
def
  increase_fee():
  try:
     con = connect_db()
     cursor = con.cursor()
     query = "update student set fee = fee * 1.10"
     cursor.execute(query)
con.commit()
print(f"{cursor.rowcount} records updated.")
       cursor.close()
       con.close()
     except Exception as e:
       print("Error:", e)
                                           OUTPUT
BEFORE FEE UPDATE
Students with Fee > 5000:
RNO: 2, NAME: Riya, DOB: 2005-08-21, FEE: 5200
RNO: 3, NAME: Sartaj, DOB: 2006-01-30, FEE: 6000
RNO: 5, NAME: Priya, DOB: 2006-03-25, FEE: 5100
Table: SUPPLIER
SUPCODE                            SNAME                                    CITY
S01                              GET ALL INC                              KOLKATA                    S02
EASY MARKET CORP                       DELHI                        S03                             DIGI
BUSY GROUP                        CHENNAI
Table: PRODUCT
PID     PNAME                           QTY        PRICE           COMPANY            SUPCODE
101      DIGITAL CAMERA 14X              120       12000         RENIX        S01    102
DIGITAL PAD 11i                100         2200          DIGI POP       S02 103   PEN DRIVE
16 GB            500        1100             STOREKING         S01 104   LED SCREEN 32
70         28000           DISPEXPERTS          S02 105     CAR GPS SYSTEM        60
12000           MOVEON               S03
1. Create Products and suppliers tables, where SUPCODE is foreign key..
2. To display the details of all the products in the ascending order of the product names (i.e., PNAME).
3. To display the product name and the price of all those products, whose price is in the range of 10,000
and 15,000 (both values inclusive).
4. To display the names of those suppliers, who are either from DELHI or from CHENNAI.
5. To display the names of the companies and the products in the descending order of the company names.
SOURCE CODE
-- PRODUCT Table
INSERT INTO PRODUCT VALUES
(101, 'DIGITAL CAMERA 14X', 120, 12000, 'RENIX', 'S01'),
(102, 'DIGITAL PAD 11i', 100, 2200, 'DIGI POP', 'S02'),
(103, 'PEN DRIVE 16 GB', 500, 1100, 'STOREKING', 'S01'),
(104, 'LED SCREEN 32', 70, 28000, 'DISPEXPERTS', 'S02'),
(105, 'CAR GPS SYSTEM', 60, 12000, 'MOVEON', 'S03');
SELECT * FROM PRODUCT
ORDER BY PNAME ASC;