COMPUTER SCIENCE
COMPUTER SCIENCE
COMPUTER SCIENCE
S. Contents
No.
Python Programs
1 Write a program in Python to input a number from the user and calculate if the given number is prime or
not.
2 Write a program in Python to input a string from the user and find out if the given string is palindrome or
not.
3 Write a program in Python, which inputs a list L of integers and displays the sum of all such integers from
the list L which end with the digit 3.
4 Write a program in Python, which input a list L of numbers and a number to be searched. If the number
exists, it is replaced by 0 and if the number does not exist, an appropriate message is displayed.
5 Write a Python program, which takes a dictionary Student as input, the dictionary Student contains
Name:(Phy,Chem,Math) as key:value pairs, program should display the average marks of all students
present in the dictionary.
6 Write a Python program to read a text file “POEM.TXT” and print the total number of vowels and
consonants separately present in the text file.
7 Write a Python code to find the size of the file “Notes.txt” in bytes, the number of lines, and number of
words and no. of character.
8 Write a Python program which reads the contents of a text file "BIOPIC.TXT" and displays the content of
the file with every occurrence of the word 'he' replaced by 'she'.
9 Write a Python program to count and display the number of lines starting with ‘A’ (Lower/Upper both
cases) present in the text file “Lines.txt”.
10 Write a Python program to count and display the number of lines that have exactly 5 words in it present
in the text file “Story.txt”.
11 Create a binary file “Student.Dat” with the name and roll number. Search for a given roll number and
display the name, if not found display appropriate message.
12 Create a binary file “Stud.dat” with roll number, name and marks. Input a roll number and update
details. Create a binary file with roll number, name and marks. Input a roll number and update details.
1. Write a user defined function CreateFile() to input data for a record and add to Book.dat .
2. Write a function CountRec(Author) in Python which accepts the Author name as parameter and
count and return number of books by the given
Author are stored in the binary file “Book.dat”
16 Write a program to create a library on your name in python and import it in a program.
17 Write a program which adds any random five even numbers in a list that falls between the highest and
the lowest number. Both highest and lowest numbers are accepted from the user.
19 A school stores records of Class XII students using a list that contains multiple lists as its elements. The
structure of each such element is [Student_Name, Marks, MainSubject].
Crate a complete program using the user-defined functions to perform the operations as mentioned
below:
(a) Push_student(): To push the Student_Name and Marks of all those students, who have Science as
MainSubject, into a Stack StudentInfo
(b) Pop_student(): To delete all items (one at a time) from the stack StudentInfo in LIFO order and
display them. Also display "Empty Stack" when there are no items remaining in the stack.
20 Write a program to connect Python with MySQL using database connectivity and perform the following
operations on data in Database:
A) Create, B) Insert, C) Fetch, D) Update and E) Delete the data.
MySQL Queries
Note: The table contains many more records than shown here. Write the following queries:
(I) To display the total Quantity for each Product, excluding Products with total Quantity less than 5.
(II) To display the orders table sorted by total price in descending order.
(III) To display the distinct customer names from the Orders table.
(IV) Display the sum of Price of all the orders for which the quantity is null.
22 Rahul, who works as a database designer, has developed a database for a bookshop. This database
includes a table BOOK whose column (attribute) names are mentioned below: BCODE: Shows the unique
code for each book.
TITLE: Indicates the book’s title.
AUTHOR: Specifies the author’s name.
PRICE: Lists the cost of the book.
Table: BOOK
23 Write SQL queries for (i) to (iv), which are based on the tables given below :
NOTE : All Dates are given in ‘YYYY-MM-DD’ format.
(i) To display total number of MALE and FEMALE Passengers
(ii) To display details of all Trains which Start from Pune Junction
(iii) To display details of all Passengers travelling in Trains whose TNO is 12030
(iv) To display the PNR, PNAME, GENDER and AGE of all Passengers whose AGE is above 50.
24 Write SQL queries for (i) to (iv), which are based on the tables.
25 Write SQL queries for (i) to (iv), which are based on the tables :
(i) To display the CODE and NAME of all SALESPERSON having “I7” Item Type Code from the table
SALESPERSON.
(ii) To display all details from table SALESPERSON in descending order of SALARY.
(iii) To display the number of SALESPERSON dealing in each TYPE of ITEM.
(Use ITCODE for the same)
(iv) To display NAME of all the salespersons from the SALESPERSON table along with their corresponding
ITEMTYPE from the ITEM table.
PRACTICAL NO. -1
# Write a program in Python to input a string from the user and find out
if the given string is palindrome or not.
OUTPUT:
PRACITICAL NO.-3
# Write a Python program to read a text file “POEM.TXT” and print the
total number of vowels and consonants separately present in the text
file.
OUTPUT:
PRACTICAL NO.- 7
# Write a Python code to find the size of the file “Notes.txt” in bytes, the
number of lines, and number of words and no. of character.
OUTPUT:
PRACTICAL NO.-8
# Write a Python program to count and display the number of lines that
have exactly 5 words in it present in the text file “Story.txt”.
OUTPUT:
PRACTICAL NO.- 11
# Create a binary file “Student.Dat” with the name and roll number.
Search for a given roll number and display the name, if not found display
appropriate message.
OUTPUT:
PRACTICAL NO.- 12
# Create a binary file “Stud.dat” with roll number, name and marks.
Input a roll number and update details. Create a binary file with roll
number, name and marks. Input a roll number and update details.
SAVING IT AS mylibrary.py
OUTPUT:
PRACTICAL NO.- 17
# Write a program which adds any random five even numbers in a list
that falls between the highest and the lowest number. Both highest and
lowest numbers are accepted from the user.
OUTPUT:
PROGRAM NO.- 18
# A school stores records of Class XII students using a list that contains
multiple lists as its elements. The structure of each such element is
[Student_Name, Marks, MainSubject].
Crate a complete program using the user-defined functions to perform
the operations as mentioned below:
(a) Push_student(): To push the Student_Name and Marks of all those
students, who have Science as MainSubject, into a Stack StudentInfo
(b) Pop_student(): To delete all items (one at a time) from the stack
StudentInfo in LIFO order and display them. Also display "Empty Stack"
when there are no items remaining in the stack.
OUTPUT:
PRACTIAL NO. -20
Note: The table contains many more records than shown here. Write the
following queries:
(I) To display the total Quantity for each Product, excluding Products
with total Quantity less than 5.
(II) To display the orders table sorted by total price in descending order.
(III) To display the distinct customer names from the Orders table.
(IV) Display the sum of Price of all the orders for which the quantity is
null.
QUERY-
(I) SELECT Product, SUM(Quantity) AS Total_Quantity
FROM ORDERS
GROUP BY Product
WHERE SUM(Quantity) >= 5;
(II)
O_ID C_Name Product Quantity Total_price
1001 Jitender Laptop 1 12000
1002 Mustafa Smartphone 2 20000
1003 Dhwani Headphone 1 1500
(III)
C_Name
Jitender
Mustafa
Dhwani
(IV)
Total_Price
null
PRACTICAL NO. - 22
QUERY-
(I)
Lowercase_Title
midnight’s children
the god of small things
a suitable boy
the white tiger
train to pakistan
(II)
Highest_Price
600
(III)
TITLE Title_lenght
midnight’s children 18
The god of small things 23
A suitable boy 15
The white tiger 15
train to pakistan 18
(IV)
B_Code Price
B003 600
B001 500
B002 450
B004 399
B005 350
PRACTICAL N0.-23
# Write SQL queries for (i) to (iv), which are based on the tables given
below :
QUERY-
(I) SELECT GENDER, COUNT(*) AS Total FROM PASSENGER GROUP BY
GENDER;
(II) SELECT * FROM TRAIN WHERE STARTING = 'Pune Junction';
(III) SELECT * FROM PASSENGER WHERE TNO = 12030;
(IV) SELECT PNR, PNAME, GENDER, AGE FROM PASSENGER WHERE AGE
> 50;
OUTPUT:
(I)
Gender Total
Male 5
Female 4
(II)
TNO TNAME STATRT END
(III)
PNR TNO PNAME GENDER AGE TRAVEL DATE
P004 12030 SK SAXENA MALE 42 2018-10-12
P005 12030 S SAXENA FEMALE 35 2018-10-12
P006 12030 P SAXENA FEMALE 12 2018-10-12
P008 12030 JK SHARMA MALE 65 2018-05-09
P009 12030 R SHARMA FEMALE 58 2018-05-09
(IV)
PNR PNAME GENDER AGE
P007 NS SINGH MALE 52
P008 JK SHARMA MALE 65
P009 R SHARMA FEMALE 58
PRACTICAL NO.- 24
# Write SQL queries for (i) to (iv), which are based on the tables.
QUERY-
(I) SELECT * FROM TRANSACT
WHERE TYPE = 'Deposit';
(II) SELECT ANO, AMOUNT FROM TRANSACT
WHERE DOT BETWEEN '2017-10-01' AND '2017-10-31';
(III)SELECT MAX(DOT) AS LastTransactionDate FROM TRANSACT
WHERE ANO = 103;
(III) SELECT ACCOUNT.ANO, ACCOUNT.ANAME, TRANSACT.DOT
FROM ACCOUNT
INNER JOIN TRANSACT
ON ACCOUNT.ANO = TRANSACT.ANO
WHERE TRANSACT.AMOUNT <= 3000;
OUTPUT:
(I)
TRNO ANO AMOUNY TYPE DOT
T002 103 3000 DEPOSIT 2017-06-01
T004 103 1000 DEPOSIT 2017-10-22
T005 101 12000 DEPOSIT 2017-11-06
(II)
ANO AMOUNT
103 1000
(III)
LastTransitionDate
2017-10-22
(IV)
ANO ANAME DOT
T001 NIRJA SINGH 2017-12--21
T002 ALI REZA 2017-06-01
T003 ROHAN GUPTA 2017-05-12
T004 ALI REZA 2017-10-22
PRACTICAL NO.- 25
# Write SQL queries for (i) to (iv), which are based on the tables :
(i) To display the CODE and NAME of all SALESPERSON having “I7” Item
Type Code from the table SALESPERSON.
(ii) To display all details from table SALESPERSON in descending order of
SALARY.
(iii) To display the number of SALESPERSON dealing in each TYPE of
ITEM.
(Use ITCODE for the same)
(iv) To display NAME of all the salespersons from the SALESPERSON table
along with their corresponding ITEMTYPE from the ITEM table.
QUERY-
(I) SELECT CODE, NAME FROM SALESPERSON
WHERE ITCODE = 'I7';
(II) SELECT * FROM SALESPERSON
ORDER BY SALARY DESC;
(IV) SELECT ITCODE, COUNT(*) AS TotalSalesperson FROM SALESPERSON
GROUP BY ITCODE;
(V) SELECT SALESPERSON.NAME, ITEM.ITEMTYPE, ITEM.TURNOVER
FROM SALESPERSON
INNER JOIN ITEM
ON SALESPERSON.ITCODE = ITEM.ITCODE;
OUTPUT:
(I)
CODE NAME
1005 ANKOKHI RAJ
1004 TARANA SEN
(II)
CODE NAME SALARY ITCODE
1002 YOGRAJ SINHA 70000 15
1001 TANDEEP JHA 60000 12
1004 TARANA SEN 55000 17
1005 ANOKHI RAJ 50000 17
1003 TENZIN JACK 45000 12
(III)
IT CODE TotalSalesPerson
17 2
15 1
12 2
(IV)
NAME ITEMTYPE TURNOVER
TANDEEP JHA BAKERY 10090000
YOGRAJ SINGH STATIONARY 3400000
TENZIN JACK BAKERY 10090000
TARANA SEN HOSEIRY 6500000
ANOKHI RAJ HOSEIRY 6500000