0% found this document useful (0 votes)
4 views

C

The document is a practical file for a Computer Science course containing various programming tasks. Each task requires writing Python programs for different functionalities, such as handling lists, reading files, and implementing data structures. The tasks cover a range of topics including prime number identification, employee details storage, file manipulation, and database connectivity.

Uploaded by

swarit4241
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)
4 views

C

The document is a practical file for a Computer Science course containing various programming tasks. Each task requires writing Python programs for different functionalities, such as handling lists, reading files, and implementing data structures. The tasks cover a range of topics including prime number identification, employee details storage, file manipulation, and database connectivity.

Uploaded by

swarit4241
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/ 29

COMPUTER SCIENCE

PRACTICAL FILE
Submitted By: Submitted To:
Swarit Kumar Ms. Swati Yadav
XII - D DLF Public School
Roll no. 33
Q1). Write a program to create a user defined function
that will accept a list of numbers as parameter and will
return a tuple of all prime numbers present in that list.

Input:

Output:
Q2). Write a program to create a list of lists for storing
employee details (name, age, department and salary)

Input:

Output:
Q3). Define a function that will take two numbers as
parameter Sum_of_series(x,n) and will evaluate and
print sum of following series: x+x^2/2! + x^3/3!
+x^4/4! …x^n/n!

Input:

Output:
Q4). Write a program to create a list of numbers,
where numbers will be generated randomly. Number
should be in between an upper limit and lower limit
where upper limit and lower limit will be taken as
input.

Input:

Output:
Q5). Write program to read a text file in python and
print its content

Input:

Output:
Q6). Given a binary file “STUDENT.DAT”, containing records of the following type:
[S_Admno, S_Name, Percentage]
Where these three values are:
a) S_Admno – Admission Number of student (string)
b) S_Name – Name of student (string)
c) Percentage – Marks percentage of student (float)
Write a function in PYTHON that would read contents of the file “STUDENT.DAT”
and display the details of those students whose percentage is above 75.

Input:

Output:
Q7). Assuming the tuple Vehicle as follows: ( vehicletype,
no_of_wheels) Where vehicletype is a string and no_of_wheels is an
integer. Write a function showfile() to read all the records present in
an already existing binary file SPEED.DAT and display them on the
screen, also count the number of records present in the file.

Input:

Output:
Q8). Assuming that a text file named TEXT1.TXT already contains some text
written into it, write a function named vowelwords(), that reads the file TEXT1.TXT
and creates a new file named TEXT2.TXT, which shall contain only those words
from the file TEXT1.TXT which don’t start with an uppercase vowel (i.e., with ‘A’,
‘E’, ‘I’, ‘O’, ‘U’). For example, if the file TEXT1.TXT contains Carry Umbrella and
Overcoat When It rains Then the text file TEXT2.TXT shall contain Carry and
When rains

Input:

Output:
Q9). Write a function in PYTHON to count the number of lines ending with a vowel
from a text file “STORY.TXT’.

Input:

Text file:

Output:
Q10). Write a function in PYTHON to count and display the number of words
starting with alphabet ‘A’ or ‘a’ present in a text file “LINES.TXT”. Example: If the
file “LINES.TXT” contains the following lines, A boy is playing there. There is a
playground. An aeroplane is in the sky. Are you getting it? The function should
display the output as 5.

Input:

Output:
Q11). Write a program in Python that defines and calls the following user-defined
functions:
(i) AddRecord() – To accept and add data of Mobile phones to a CSV file
‘Mobile_Phones.csv’. Each record consists of a list with field elements as
ModelNo, MobileName, Manufacturer and Price to store model number, mobile
name, manufacturer and price respectively.
(ii) Find() – To search the records of mobiles manufactured by Apple present in the
CSV file named ‘Mobile_Phones.csv’.

Input:
Output:
Q12). Write a program to write data in CSV file of a customer as
follows: [customer_id, customer_name, membership_type ]

Input:

Output:
Q13). Write a menu based program to store customer data of a bank. Data will be
as follows: [accno, name, address, balance,branch] Menu will be as follows:
1. Add a new customer detail
2. Update a customer detail
3. Delete a customer detail
4. Search a customer with accno
5. Display data of all customers
6. Exit

Input:
Output:
Q14). A list contains the following record of a Hostel: [Hostel_No, Total_Students,
Total Rooms]
Write the following user defined functions to perform given operations on the
stack named ‘Hostel’:
(i) Push_element() - To push an object containing Hostel_No and Total Students
along with Total Rooms to the stack
(ii) Pop_element() - To pop the objects from the stack and display them. Also,
display “Stack Empty” whenthere are no elements in the stack.

Input:

Output:
Q15). Write a program to implement a Stack for book_details (book name : book
price) where book name is a key and book price is value. Write a function in
Python, Push(book_details) where book_details is a dictionary containing the
details of books– {book_name : book_price}. The function should push the names
of those books in the stack which have price greater than 500. Also display the
count of books pushed into the stack. For example: If the dictionary contains the
following data: books={"Python":560,"Java":450,"MySQL":330,"Web
Development":725}
The stack should contain Python and Web Development.
The output should be: The count of books in the stack is 2.

Input:

Output:
Q16). Write a program to take two number as input and display any random
number between those two numbers.

Input:

Output:
Q17). Write a program to create a simple chatbot using dictionary to store data
and random number to generate response.

Input:

Output:
Q18). Write a program to take a number as input and display its square root using
function of math module.

Input:

Output:
Q19). Write a program to take a float with 5 decimal digits as input and display
after rounding off that value to 2 decimal places using function of math module.

Input:

Output:
Q20). Write the code to reads the following record from the table named
Employee and displays only those records who have a Salary greater than 75000:
EmpNo – integer
EmpName – string
Designation – string
Salary – integer
Note the following to establish connectivity between Python and MySQL:
a. Username is root
b. Password is sales_emp
c. The table exists in a MySQL database named “Office”.

Answer:
Q21).Write the code to establish connectivity between python and MYSQL.
To create a new table with following details:
INPUT:
OUTPUT:

You might also like