INDEX
S. NO PROGRAM SIGN
1 Define the following user-defined functions
a. GetStory(), to create a text file named STORY.TXT, which should
contain text lines entered by the user.
b. ViewStory(), to read and display the entire content of text file
STORY.TXT on the screen.
c. Words(), to read and display each word of the text file
STORY.TXT in different lines on the screen.
Write menu driven code to call the above functions
2 Write a menu driven program to do the following functions:
a. CreateNotes() - to create a text file NOTES.TXT to have text entered
by user as
b. CountAVD( )- to read the contents of the text file NOTES TXT
and count andprint the number of Alphabets, Vowels and Digits
present in the file
c. Show Notes()- to display the contents of text file NOTES TXT
d. RevText()- to read the contents of the text file NOTES TXT, and
print reverse of those lines which start with an alphabet 'T'
Write menu driven code to call the above functions
3 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.
4 Write a Python code with the following functions.
a. AddValues(L) - To add integer values entered by the user in the list
L
b. DispValues(L) - To display values of L
c. SwapPair(L)- To re-arrange the content of L by swapping each
pair of adjacentneighboring values
d. SwapHalf(L)- To re-arrange content of L by swapping first half of
the list with second half of the list
Write menu driven code to call the above functions.
5 Write a Python code with the following functions:
a. AddValues(L) - To add integer values entered by the user in the list
L
b. DispValues(L) - To display values of L
c. SwapPair(L) - To re-arrange the content of L by swapping each
pair of adjacent neighbouring values
d. SwapHalf(L) - To re-arrange content of L by swapping first half of
the list with second half of the list
Write menu driven code to call the above functions
6 Write a menu driven program to do the following operations:
a. Factorial(n), to find and return factorial of a number n which is
passed as parameter.
b. Reverse(n), to find and display reverse of a number which is passed
as parameter.
c. IsPrime(n), to find that the given number is prime, composite or not
prime nor composite.
Write menu driven code to call the above functions
7 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.
8 Write a Python code with the following functions performing mentioned
operations on a binary file “ACCOUNTS.DAT” 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 binary file named ACCOUNTS.DAT.
b) DisplayAll( ) to display the details of all Account Holders from
ACCOUNTS.DAT
c) Transact( ), to perform a transaction i.e. Deposit or Withdraw an Amount
in an Account Holders Balance whose Acno is entered by the user from
ACCOUNTS.DAT.
Note: an Account Holder must always have a minimum Balance of Rs
500 in his/her Account.
d) BankBalance() to find and return the sum of Balance of all the account
holders from ACCOUNTS.DAT
Write menu driven code to call the above functions.
9 Write a menu driven program to do the following operations on a binary file
EMPLOYEE.DAT:
a) Create( ) – Accept EMPNO, NAME and SALARY from user and then
store in binary file till user wants to store.
b) Display( ) – Show the information of all the employees in tabular form.
c) Search( ) – Display the information of employee whose EMPNO is
entered by user. If EMPNO not found the display message “No Such
Employee Exist”
d) Modify( ) – Change the Name and Salary of employee whose EMPNO is
passed as parameter.
e) Delete( ) – Delete the information of employee whose Name is entered
by user. If Name not found the display message “No Such Employee
Exist”
Write menu driven code to call the above functions.
10 Write a menu driven program to do the following operations on a csv file
"MEMBER.CSV":
a) To add details of new members (Mno, Name, Fee, Type) in the csv file
with the content of the user.
b) To display the details of all the members from the csv file
c) To search for a member matching with Mno entered by the user and
display the details of the member from the csv file
d) To calculate and display the average Fee from the csv file.
Write menu driven code to call the above functions.
11 Write a menu driven program to do the following operations on a csv file
"STOCK.CSV":
a) To add details of new items (INO, ITEM, PRICE, QTY) in the csv file
with the content of the user
b) To display the details of all the items along with stock value of each item
(PRICE*QTY) from the csv file
c) To search for a item matching with Ino entered by the user and then
display the details of the items from the csv file
d) To display all names of all items, whose name starts with "P" letter.
e) Copy all the items to a CSV file "REORDER.CSV" whose quantity is
less than 10 in stock and then display the CSV file "REORDER.CSV".
Write menu driven code to call the above functions.
12 Write a menu driven program to do the following operations on a csv file
"CADETS.CSV".
a) To add details of new cadets (CNO, NAME, GENDER, AGE, HEIGHT)
in the CSV file with the content of the user
b) To display the details of all the cadets from the CSV file
c) To display the detail of all the cadets whose gender is passed as
parameter from the CSV file
d) To Modify the Age and Height of cadet whose Candidate Number (Cno)
is entered by user.
Write menu driven code to call the above functions.
13 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
Write menu driven code to call the above functions.
14 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.
15 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 prints them. Also, the function displays
'Stack Empty' when there are no elements in the stack.
(iii) Display(Stu_Stk) : It display all the elements of stack Stu_Stk.
Write menu driven code to call the above functions.
16 A list, NList contains 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 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 display all the elements of stack travel.
Write menu driven code to call the above functions.
17 A table, named STATIONERY has the following structure:
Field Type
ItemNo Int(5) Primary key
ItemName Varchar (20)
Price Float(8,2)
Qty Int
Assume the following for Python-Database connectivity:
Host: localhost, User: root, Password: Pencil
Write the following Python functions to perform the specified operation:
A. Create() – to create a database ITEMDB, open the database and then
create the above defined table STATIONERY.
B. Insert() – to store a set of stationery items from user input in the
stationery table, till user wants to store.
18 Sartaj has created a table named Student in MYSQL database,
SCHOOL:
RNO(Roll number )- integer, NAME(Name) - string, DOB (Date of birth) –
Date, FEE – float
Assume the following for Python-Database connectivity:
Host: localhost, User: root, Password: Sgs
Write user defined functions to do the following operations:
a) Display the records of students whose fee is more than 5000.
b) Increase the Fee of all students by 10%.
19 Write SQL commands for Teacher and Student tables.
20 Write SQL commands for Supplier and Product Tables.
PROGRAM NO:
Date:
Write a Python code with the following functions.
a. AddValues(L) - To add integer values entered by the user in the list L
b. DispValues(L) - To display values of L
c. SwapPair(L)- To re-arrange the content of L by swapping each pair of adjacent neighbouring
values
d. SwapHalf(L)- To re-arrange content of L by swapping first half of the list with second half of the
list
Also, call the above functions in the order as a, b, c, and d
SOURCE CODE
L=[]
def AddValues(L):
while True:
integer = int(input('Enter an integer : '))
L.append(integer)
choice = input('More [Y/N] ? ')
if choice=='N':
break
def DispValues(L):
print('List is : ',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]
AddValues(L)
DispValues(L)
SwapPair(L)
DispValues(L)
SwapHalf(L)
DispValues(L)
OUTPUT
Date: 6.9.22