0% found this document useful (0 votes)
21 views7 pages

All Practical Questions Session 2023-24

Uploaded by

r66120746
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views7 pages

All Practical Questions Session 2023-24

Uploaded by

r66120746
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Practical Questions

Python
1. WAUDF which accepts a list of string, N, as a parameter to a function PushAV( ) and pushes all the strings which
have no vowels present in it, into a list named NoVowel. Display the elements of NoVowel by popping all the
elements from it. When the list is/becomes empty, display the message “STACK EMPTY”
Use menu driven program for the same.
2. WAUDF which accepts a list of integers, N, as a parameter to a function Push3_5( ) and pushes all the integers
which ends with either 3 or 5, into a list named LST. Display the elements of LST by popping all the elements from
it. When the list is/becomes empty, display the message “STACK EMPTY”
Use menu driven program for the same.
3. WAUDF which accepts a list of integers, N, as a parameter to a function Push3_5( ) and pushes all the integers
which is divisible with either 3 or 5, into a list named LST. Display the elements of LST by popping all the elements
from it. When the list is/becomes empty, display the message “STACK EMPTY”
Use menu driven program for the same.
4. Write a menu driven program to do the following tasks:
a. Method CREATEFILE( ) to Create a text file TESTFILE.TXT with some contents.
b. Display the entire file.
c. method COUNTLINES() to read lines from the text file TESTFILE.TXT and display the lines which are not
starting with any vowel.
5. Write a menu driven program to do the following tasks:
a. Method CREATEFILE( ) to Create a text file TESTFILE.TXT with some contents.
b. Display the entire file.
c. method EUCOUNT() to read the file and display the total number of occurrences of E and T separately,
from the text file TESTFILE.TXT.
6. A list contains following record of a customer:
[Cust_name, Phone, City]
Write the following user defined functions to perform given operations on the stack named 'status':
(i) Push_element()- To Push an object containing name and Phone number of customers who live in Goa to the
(ii) Pop_element() - To Pop the objects from the stack and display them. Also, display "Stack Empty" when there
are no elements in the stack.
7. Write a function in Python, Push(SItem) where, SItem is a dictionary containing the details of stationary items
{Sname:price}.
(i)The function Push_element( )- To push the names of those items in the stack who have price greater than 75.
Also display the
count of elements pushed into the stack.
(ii) Pop_element() - To Pop the objects from the stack and display them. Also, display "Stack Empty" when there
are no elements in the stack.
8. Write a menu driven program to do the following tasks:
a. Method CREATEFILE( ) to Create a text file TESTFILE.TXT with some contents.
b. Display the entire file.
c. method DISPLAYWORDS() to read lines from the text file TESTFILE.TXT and display those words which are
less than 4 characters.
9. Write a menu driven program to do the following tasks:
a. Method CREATEFILE( ) to Create a text file TESTFILE.TXT with some contents.
b. Display the entire file.
c. method COUNTHISHER() to read the text file TESTFILE.TXT and display the words His/Her (not case
sensitive).
10. Write a menu driven program to do the following tasks:
a. To push any student’s information to stack
b. To display all the elements of the stack
11. Write a menu driven program to do the following tasks:
a. Method CREATEFILE( ) to Create a text file SPORTS.DAT which contains EventName and ParticipantName.
b. Method READ( file ) to display the content of the file, whose name is accepted as argument.
c. method COPY() to read the contents of binary file SPORTS.DAT and create the file ATHELITICS.DAT copying
only those records from SPORTS.DAT where the event name is “Athelitics”.
12. Write a menu driven program to do the following tasks:
a. Method CREATEFILE( ) to Create a text file PARA.TXT with some contents.
b. Display the entire file.
c. Method COUNT() to read the text file PARA.TXT and searches for a character and reports the number of
occurrence of a character in the file.
13. Write a menu driven program to do the following tasks:
a. Method CREATEFILE( ) to Create a text file PARA.TXT with some contents.
b. Display the entire file.
c. Method REVERSE() that overwrites the contents of the text file PARA.TXT with its reverse contents.
14. Write a menu driven program to do the following tasks:
a. Method CREATEFILE( ) to Create a text file PARA.TXT with some contents.
b. Display the entire file.
c. Method COUNT() to read the text file PARA.TXT and count and display number of lines starting with a
digit.
15. Write a program to implement a stack for these book details ( bookno, bookname ). Implement push and display
operations.
16. Write
a. Add new (Book) to Add a new Book
b. Remove(Book) to Remove a Book
from a List of Books, considering them to act as PUSH and POP operations of the data structure stack.
17. Arr is a stack implemented by a list of numbers.
a. Write a function in Python PUSH(Arr). From this list push all numbers divisible by 5 into a stack
implemented using a list. Display the stack if it has at least one element, otherwise display appropriate
error message.
b. Write a function in Python POP(Arr), where The function returns the value deleted from the stack.
18. Alam has a list containing 10 integers. You need to help him create a program with separate UDFs to perform
operations based on list.
a. Traverse the content of the list and push the even numbers into the stack.
b. Pop and display the content of the stack.
19. Write a program that checks whether an input string is a palindrome using stacks. Write two functions:
a. Pushstr()
b. Popstr() also write the main module also.
20. A csv file students.csv contains students name and score. Write a function
a. Score( ) - to read student’s name and print the score from the file.
b. Count( ) – to count the number of records and column names present in the file.
21. Write a menu driven program to do the following tasks:
a. Method CREATEFILE( ) to Create a text file PARA.TXT with some contents.
b. Display the entire file.
c. Method COUNT() that counts the number of lines in the text file PARA.TXT which is starting with an
alphabet “AN”
22. A list contains the following record of a customer:
[Customer_name, Phone_no, City]
Write the following UDFs to perform the given operations on the stack named ‘status’.
a. Push_element() – to push an object containing name and phone number of the customers who live in
‘Goa‘ to the stack.
b. Pop_element() – to pop the objects from the stack and display it. Also, display “Stack Empty” when there
are no elements in the stack.
MY-SQL and PYTHON – MYSQL Connectivity Questions

23. The code given below inserts the following record in the table Student:
RollNo-integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:
 Username is root
 Password is tiger
 The table exists in a MYSQL database named school.
 The details (Ro11No, Name, Class and Marks) are to be accepted from the user.

Write the following missing statements to complete the code:


Statement1-to use the database
Statement 2-to form the cursor object
Statement 3- to execute the command that inserts the record in the table Student.
Statement 4- to add the record permanently in the database

import mysql.connector as mysql


def sql_data():
con1=mysql.connect(host=”localhost”,user=”root”,password=”tiger”,database=_________”) #Statement 1
mycursor= ____________ #Statement2
rno = int (input ("Enter Roll Number :: "))
name = input ("Enter name 11 ")
class = int (input ("Enter class :: "))
marks = int (input ("Enter Marks : : "))
querry = "insert into student values ({}.'{}'.{}.{})". format (rno, name, class, marks)
_____________________ #Statement 2
_____________________ #Statement 3
print ("Data Added successfully")
24. The code given below reads the following record from the table named student and displays only those
records who have marks greater than 75:
RollNo-integer
Name - string
Class-integer
Marks-integer
Note the following to establish connectivity between Python and MYSQL:
 Username is root
 Password is tiger
 The table exists in a MYSQL database named school.
Write the following missing statements to complete the code:
Statement1- to import mysql.connector library and give an alais as mysql
Statement 2-to form the cursor object
Statement 3- to execute the query that extracts records of those students whose marks are greater than 75.
Statement 4- to read the complete result of the query (records whose marks are greater than 75) into the
object named data, from the table student in the database.

___________________________ #Statement 1
def sql_data():
con1 = mysql.connect (host="localhost", user-"root", password="tiger", database="school")
mycursor = _______________ #Statement 2
print ("Students with marks greater than 75 are: ”)
_______________________ #Statement 3
Data=__________________ #Statement 4
for i in Data:
print(i)
print( )
25. Consider the table Teacher in which Tina wants to add two rows. For this, she wrote a program in which some
code is missing. Help her to complete the following code.
import mysql.connector
mycon = mysql.connector.connect (host = "________", User = "root", passwd = "system", database=” test”) #Line1
cursor=con.cursor( )
sql=”Insert ___ Teacher (t_id, fname, lname,hire_data, salary, subject) values(%S, %S, %S, %S, %S, %S)” #Line2
VAL=[(1,”Vibha”,”Bajpai”,’12-12-2021’,20000,”Python”), (1,”Rekha”,”Sharma”,’10-11-2021’,120000,”Math”)]
try:
cursor.executemany(sql,VAL)
mycon.__________( ) #Line 3
except:
mycon.rollback() #Line 4
(i) What should be come in the blank at the line1?
(ii) What should be come in the blank at the line2?
(ii) Which function will be filled in the blank at line3?
(iii) Which function will be filled in the blank at line4?

26. Consider the following tables GAMES and PLAYER and answer (b) and (c) parts of this question:
Table: GAMES

GCode GameName Type Number PrizeMoney ScheduleDate


101 Carom Board Indoor 2 5000 23-Jan-2004
102 Badminton Outdoor 2 12000 12-Dec-2003
103 Table Tennis Indoor 4 8000 14-Feb-2004
105 Chess Indoor 2 9000 01-Jan-2004
108 Lawn Tennis Outdoor 4 25000 19-Mar-2004
Table: PLAYER
PCode Name GCode
1 Nabi Ahmad 101
2 Ravi Sahai 108
3 Jatin 101
4 Nazneen 103
(b) Write SQL commands for the flowing statements:
(i) To display the name of all GAMES with their GCodes
(ii) To display details of those GAMES which are having PrizeMoney more than 7000.
(iii) To display the content of the GAMES table in ascending order of Schedule Date.
(iv) To display sum of PrizeMoney for each Type of GAMES
27. Consider the following tables Stationary and Consumer. Write SQL commands for the statement (i) to (iv) and
output for SQL queries (v) to (viii):
Table: Stationary

S_ID StationaryName Company Price


DP01 Dot Pen ABC 10
PL02 Pencil XYZ 6
ER05 Eraser XYZ 7
PL01 Pencil CAM 5
GP02 Gel Pen ABC 15
Table: Consumer

C_ID ConsumerName Address S_ID


01 Good Learner Delhi PL01
06 Write Well Mumbai GP02
12 Topper Delhi DP01
15 Write & Draw Delhi PL02
16 Motivation Banglore PL01
(i) To display the details of those consumers whose Address is Delhi.
(ii) To display the details of Stationary whose Price is in the range of 8 to 15. (Both Value included)
(iii) To display the ConsumerName, Address from Table Consumer, and Company and Price from table Stationary,
with their corresponding matching S_ID.
(iv) To increase the Price of all stationary by 2.

28. Consider the following tables GARMENT and FABRIC. Write SQL commands for the statements (i) to (iv) and give
outputs for SQL queries (v) to (viii).
Table : GARMENT

GCODE DESCRIPTION PRICE FCODE READYDATE


10023 PENCIL SKIRT 1150 F03 19–DEC–08
10001 FORMAL SHIRT 1250 F01 12–JAN–08
10012 INFORMAL SHIRT 1550 F02 06–JUN–08
10024 BABY TOP 750 F03 07–APR–07
10090 TULIP SKIRT 850 F02 31–MAR–07
10019 EVENING GOWN 850 F03 06–JUN–08
10009 INFORMAL PANT 1500 F02 20–OCT–08
10007 FORMAL PANT 1350 F01 09–MAR–08
10020 FROCK 850 F04 09–SEP–07
10089 SLACKS 750 F03 20–OCT–08
Table : FABRIC
FCODE TYPE
F04 POLYSTER
F02 COTTON
F03 SILK
F01 TERELENE
(i) To display GCODE and DESCRIPTION of a each dress in descending order of GCODE.
(ii) To display the details of all the GARMENTs, which have READYDATE in between 08–DEC–07 and 16–JUN–08 (inclusive
of both the dates).

(iii) To display the average PRICE of all the GARMENTs, which are made up of FABRIC with FCODE as F03.

(iv) To display FABRIC wise highest and lowest price of GARMENTs from DRESS table. (Display FCODE of each GARMENT
along with highest and lowest price)

29. Consider the following table RESORT and OWNER and answer questions (A) and (B)
Table : RESORT

RCODE PLACE RENT TYPE STARTDATE


R101 GOA 15000 5 Star 23 Jan 2008
R102 HIMANCHAL 12000 4 Stat 12 Nov 2007
R103 KERALA 12500 5 Star 18 Mar 2006
R104 HIMANCHAL 10900 3 Star 09 Jan 2007
R105 GUJARAT 8000 2 Star 29 Apr 2008
R106 GOA 16000 7 Star 03 Mar 2003
R107 ORISSA 9600 3 Star 16 Oct 2005
R108 KERALA 12000 4 Star 12 Aug 2006
R109 HIMANCHAL 8500 2 Star 25 Jan 2004
R110 GOA 12800 4 Star 23 Feb 2008

Table : OWNEDBY

PLACE OWNER
GOA SUN VILLAGE
KERALA KTDC
HIMANCHAL KALRA RESORTS
GUJARAT KINJAL GROUP
ORISSA OTDC
(A) Write SQL commands for the following statements:
(i) to display the RCODE and PLACE of all ‘2 Star’ resorts in the alphabetical order of the place
from table RESORT.
(ii) to display the maximum & minimum rent for each type of resort from table RESORT.
(iii) to display the details of all resorts which are started after 31-Dec-04 from table RESORT.
(iv) to display the owner of all ‘5 Star’ resorts from tables RESORT and OWNEDBY.
Interfacing with Python

You might also like