COMPUTER SCIENCE IMPORTANT PROGRAMS FOR
PRACTICAL EXAM
NOTE:1)QUESTIONS WILL BE ASKED FROM THIS
ONLY.
2)ALL THE QUESTIONS ANSWER YOU WILL GET IT IN
THE PRACTICAL FILE.
ONLY 1 QUESTION IS OUT OF FILE ANSWER IS GIVEN
BELOW.
a) Write a python program to Sort Python Dictionary by Key or Value
d = {'ravi': 10, 'rajnish': 9, 'sanjeev': 15}
myKeys = list(d.keys())
myKeys.sort()
# Sorted Dictionary
sd = {i: d[i] for i in myKeys}
print(sd)
OUTPUT
{'rajnish': 9, 'ravi': 10, 'sanjeev': 15}
S.No. Area Marks
1 Python Program 8
2 Python with MySQL 4
connectivity
3 Report file of programs 7
4 Project 8
5 Viva 3
Total 30
SET I
PYTHON PROGRAM
Q1.)a)A stack of student’s information contains Rollno, Name and Grade. Write
a python program to create a stack containing students’ information forthe
number of students entered by the user. Now create the following methods with
created stack asan argument to display and update the stack.
display(stack) – To display the information of all the students saved in stack.
Push(stack) – To display previously saved information, accept new information
for a studentand update the stack.
b) Write a Python function to calculate the factorial of a number (a non-
negative integer). The function accepts the number as an argument.
SQL QUERIES
Q2)
Write SQL commands for the queries(i) to (iii) and output for (iv) based on a table
COMPANY and CUSTOMER.
COMPANY
CID NAME CITY PRODUCTNAME
111 SONY DELHI TV
222 NOKIA MUMBAI MOBILE
333 ONIDA DELHI TV
444 SONY MUMBAI MOBILE
555 MADRAS MOBILE MOBILE
666 DELL DELHI LAPTOP
CUSTOMER
CUSTID NAME PRICE QTY CID
101 ROHAN 70,000 20 222
102 DEEPAK 50,000 10 666
103 MOHAN 30,000 5 111
104 SAHIL 35,000 3 333
105 NEHA 25,000 7 444
106 SONAL 20,000 5 333
107 ARUN 50,000 15 666
1.To display th e name of the companies in reverse alpha betical order.
To increase the prize by 1000 for those customer whose name starts with
“S”?
To add one more column totalprice with decimal(10,2) to the table
customer.
SELECT COUNT(*),CITY FROM COMPANY GROUP BY CITY;
SET:2
PYTHON PROGRAM
Q1)
a) Write a python program to write a function calc() such that it can
accept a variable length of argument and display the sum of all
arguments value.
b) Write a Python program to get item details (code,description and price) for
multiple items from the user and create a csv file by writing all the item details in
one go.
SQL QUERIES
Q2) Write SQL commands for (i) to (iv) and find outputs for SQL queries(v) to
(vi),which are based on the tables.
TABLE:VEHICLE
VCODE VEHICLETYPE PERKM
V01 VOLVOBUS 150
V02 ACDELUXE BUS 125
V03 ORDINARYBUS 80
V05 SUV 30
TABLE:TRAVEL
CNO CNAME TRAVELDATE KM VCODE NOP
101 NIWAL 2015-12-13 200 V01 32
103 FREDRICK SYM 2016-03-21 120 V03 45
105 HITESH JAIN 2016-04-23 450 V02 42
102 RAVI 2015-02-10 65 V04 2
107 JOHN MALINA 2016-02-10 80 V02 40
104 SAHANIBHUTI 2016-01-28 90 V05 4
I) To display CNO,CNAME,TRAVELDATE from the table TRAVEL in
descending order CNO.
II) To display the CNAME of all customers from the table TRAVEL who are travelling
by vehicle with code V01 or Vo2.
III) To display the CNO and CNAME of those customers from the table
TRAVEL who travelled between ‘2015-05-01’ and ‘2015-12-31’.
IV) To display all the details from table TRAVEL for the customers who have
travel distance more than 120KM in ascending order of NOP.
V) SELECT COUNT(*) VCODE FROM TRAVEL GROUP BY VCODE HAVING
COUNT(*)>1;
VI) SELECT DISTINCT VCODE FROM TRAVEL:
SET3
PYTHON PROGRAM
Q1.a)Write a python program to pass list to a function and double the odd
values and half even values of a list and display list element after changing.
b)Write a program using python to get 10 players name and their score. Write the
input in a csv file. Accept a player name using python. Read the csv file to display
the name and the score. If theplayer’s name is not found give an appropriate
message.
SQL QUERIES
Query I - Create a database ‘School’.
Query II - Create a table ‘Student’ with followingattributes in School database:
sid– number (should not accept a duplicate value)sname – Text (Could be maximum
30 character long)
gender – Should accept only 1 character either MorF
mark– Should allow decimal values but cannot bemore than 100 or less than 0.
Query III – Enter the same values as given in below.
Sid Sname Gender Mark
101 Neha F 97
111 Ria F 67
231 Mohan M 78
124 Rohan M 94
121 Misha F 92
Query IV - Add 2 new columns: city varchar(15),phone varchar(10).
SET4
PYTHON PROGRAM
Q1)a) Take a sample text file and find the mostcommonly occurring word.
Also, find the frequencies of words in the text file.
b) Write a Python program input n numbers in tuple and pass it to function
to count how many even and odd numbers are entered.
SQL QUERIES
1) Write SQL commands for the queries(i) to (iii) and output for (iv) based on a table
COMPANY and CUSTOMER.
COMPANY
CID NAME CITY PRODUCTNAME
111 SONY DELHI TV
222 NOKIA MUMBAI MOBILE
333 ONIDA DELHI TV
444 SONY MUMBAI MOBILE
555 MADRAS MOBILE MOBILE
666 DELL DELHI LAPTOP
CUSTOMER
CUSTID NAME PRICE QTY CID
101 ROHAN 70,000 20 222
102 DEEPAK 50,000 10 666
103 MOHAN 30,000 5 111
104 SAHIL 35,000 3 333
105 NEHA 25,000 7 444
106 SONAL 20,000 5 333
107 ARUN 50,000 15 666
2. To display the name of the companies in reverse alphabetical order.
3. To increase the prize by 1000 for those customer whose name starts with “S”?
4. To add one more column totalprice with decimal(10,2) to the table
customer.
5. SELECT COUNT(*),CITY FROM COMPANY GROUP BY CITY;
SET 5
PYTHON PROGRAM
a) Write a python program to Sort Python Dictionary by Key or Value
d = {'ravi': 10, 'rajnish': 9, 'sanjeev': 15}
myKeys = list(d.keys())
myKeys.sort()
# Sorted Dictionary
sd = {i: d[i] for i in myKeys}
print(sd)
OUTPUT
{'rajnish': 9, 'ravi': 10, 'sanjeev': 15}
b) Write a python program to create a binary file with name and roll number.
Search for a given roll number and display name, if not found display
appropriate message.
SQL QUERIES
2) Query I - Create a database ‘School’.
Query II - Create a table ‘Student’ with following attributes in School database:
sid – number (should not accept a duplicate value)
sname – Text (Could be maximum 30 character long)
gender – Should accept only 1 character either M or F
mark – Should allow decimal values but cannot be more than 100 or less than0.
Query III – Enter the same values as given in below table:
Sid Sname Gender Mark
101 Neha F 97
111 Ria F 67
231 Mohan M 78
124 Rohan M 94
121 Misha F 92
Query IV – Display student data in descending order of sid.
Query V – Display the number of students genderwise.
SET6
PYTHON PROGRAM
Q1a) Write a program to copy all the lines that contain the character `a' in
a file and write it to another file.
b)Define push(), pop() and display() methods inPython to operate on stack of
numbers.
SQL QUERIES
2)I - Create a database ‘School’.
Query II - Create a table ‘Student’ with following attributes in School database:
sid – number (should not accept a duplicate value)
sname – Text (Could be maximum 30 character long)
gender – Should accept only 1 character either M or F
Query III - Add 2 new columns: city varchar(15),
phone varchar(10).
Query IV - Redefine the size of city to 20 characters.
Query V - Drop the attribute city.