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

Output based questions string XII CS

The document outlines a series of programming tasks primarily focused on Python functions for file handling, data manipulation, and database connectivity. It includes exercises for reading and writing to text, binary, and CSV files, as well as operations on data structures like stacks and dictionaries. Additionally, it discusses network setup considerations for institutions and provides specific coding challenges related to database operations and data processing.

Uploaded by

moammed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Output based questions string XII CS

The document outlines a series of programming tasks primarily focused on Python functions for file handling, data manipulation, and database connectivity. It includes exercises for reading and writing to text, binary, and CSV files, as well as operations on data structures like stacks and dictionaries. Additionally, it discusses network setup considerations for institutions and provides specific coding challenges related to database operations and data processing.

Uploaded by

moammed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

OUTPUT BASED QUESTIONS: 6.

1.

7.

2.

8.

3.

9.

4.

10.

5.

11.
12.

16. What possible outputs(s) are expected to be


displayed on screen at the time of execution program
from the following code? Also specify the maximum
13. values that can be assigned to each of the variables
BEGIN and END.

17. What possible outputs(s) are expected to be


displayed on screen at the time of execution of the
program from the following code? Also specify the
maximum values that can be assigned to each of the
14.
variables BEGIN and END.

15. What possible outputs(s) are expected to be


displayed on screen at the time of execution of the
program from the following code? Also specify the
maximum values that can be assigned to each of the
variables FROM and TO.
Text File // Binary File // CSV File // Stack Program
1. Write a user defined function in python that displays the number of lines starting with 'H' in the file para.txt
2.Write a function countmy() in python to read the text file "DATA.TXT" and count the number of times "my"
occurs in the file. For example if the file DATA.TXT
3. Write a Python program to read text file “story.txt” line by line and display each word separated by “#”.
4. Write a method/function BIGWORDS() in Python to read contents from a text file CODE.TXT, to count and
display the occurrence of those words, which are having 7 or more alphabets..
5. Write a user-defined function named Count() that will read the contents of text file named “Report.txt” and count
the number of lines which starts with either “I” or “M”.
6. A list contains following record of a student: [student_name, marks, subject]
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 marks of a student who scored more than 75 marks in
‘CS’ to 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.
cust = [["Danish",80,"Maths"], ["Hazik",79,"CS"], ["Parnik",95,"Bio"], ["Danish",70,"CS"], ["Sindhu",99,"CS"]]
7. Write a Python program to create a stack of student’s records which contains [Roll.no, Name, Marks].
a. Write function PUSH to add record into the stack and
b. Write function DISPLAY to display those students whose name is started with A.
8. A dictionary stu contains rollno and marks of students. Two empty list stack_roll and stack_mark will be used as
stack. Two functions push_stu() and pop_stu() are defined and perfom the following operations:
(a) Push_stu() :- It reads dictionary stu and add keys into stack_roll and values into stack_marks for all students who
secured more than 60 marks.
(b) Pop_stu() :- it removes last rollno and marks from both list and print “underflow” if there is nothing to remove
For example stu={1:56,2:45,3:78,4:65,5:35,6:90} values of stack_roll and stack_mark after push_stu()
[3,4,6] and [78,65,90]
9. A binary file “ITEMS.DAT” has structure (ID, GIFT, Cost). Write a function to write more items in ITEMS.DAT
ii. Write a function Economic() in Python that would read contents of the file “ITEMS.DAT” and display the
details of those ITEMS whose cost is greater then 2500.
10. A binary file “EMPLOYEE. DAT’ has structure as empcode, Name and Salary. Write a function count() that
would read content of the file “EMPLOYEE.DAT” and display the details of all those employee whose salary is
more than 50000.
11. A binary file “SCHOOL.DAT” has structure [Roll_Num, Name, Percentage]
i) Write a function Count_Rec() in Python that would read contents of the file “SCHOOL.DAT” and display the
details of those students whose percentage is below 33 . Also display number of students scoring below 33%.
12. A binary file named “EMP.dat” has some records of the structure
[EmpNo, EName, Post, Salary]
(a)Write a user-defined function named NewEmp() to input the details of a new employee from the user and store
it in EMP.dat.
(b) Write a user-defined function named SumSalary(Post) that will accept an argument the post of employees &
read the contents of EMP.dat and calculate the SUM of salary of all employees of that Post.
13. Write a program in Python that defines and calls the following user defined functions:
i. Add(): to add the record of an animal to a csv file “animal.csv”.
Each record should be with field elements [animalname, animaltype, animalfood]
ii. Search(): to print all the animal names who eat grass as their food.
14. Write a Program in Python that defines and calls the following user defined functions:
a) ADD() – To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of a list with
field elements as empid, name and mobile to store employee id, employee name and employee salary respectively.
b) COUNTR() – To count the number of records present in the CSV file named ‘record.csv’.
15. Anita writing a program to create a csv file “abc.csv” which contain user id and name of the beneficiary. She
has written the following code. As a programmer help her to successfully execute the program.

16.

17.

18. Note the following to establish connectivity between Python and MYSQL:
Username is root , Password is 123 , Database : Company , Table : Employee
( Eno integer , Ename Varchar ,Department Varchar , Salary Integer ).
Write the following missing statements to complete the code:
import ________ as mysql # Statement 1
def disp_data():
con=mysql.__________ # Statement 2
mycursor=con.___________ # Statement 3
mycursor.execute(„select * from employee‟)
data=mycursor._______ # Statement4
print(“Total Records Selected”,________) # Statement5
con.close()
Statement 1 – Use the suitable package ,
Statement 2 – Establish the connection
Statement 3 – Create the cursor Object ,
Statement 4 – extract all the records from the result set
Statement5 – Display the row count
19. Note the following to establish connectivity between Python and MYSQL:
Username is root , Password is tiger , Database : Company , Table : Employee
( Eno integer , Ename Varchar ,Department Varchar , Salary Integer ) .
The given code is used to insert the details to table which are accepted from the user.
Write the following missing statements to complete the code:

Statement 1 – Create the cursor Object,


Statement 2 – query to insert the record in to the table
Statement 3 –Command to add record permanently in the table ,
Statement 4 –Display the row count.
Statement5- Terminate the connection object
20. Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is password
Database : Company
Table : Employee( Eno integer , Ename Varchar ,Department Varchar , Salary Integer )
The given code is used to display employee details using the department which is input by user
Write the following missing statements to complete the code:

Statement 1 – Provide the attributes to establish the connection


Statement 2 – Create the cursor Object
Statement 3 – query to select records of employees according to the department.
Statement 4- read first record from the result set,
Statement 5 – read rest of the records from result set
21. A table, named BOOK, in LIBRARY database, has the following structure:
Field Type
BNo int(4)
BName varchar(15)
Price float
Qty int(11)
Write the following Python function to perform the specified operation:
Add( ) : To input details of a Book and store it in the table BOOK.
Display( ) : The function should retrieve and display all records from the BOOK table where the Price is greater
than 180. Assume the following for Python-Database connectivity:
Host: localhost, User: root, Password: Library
22. Write a function EvenOdd(L) in python, to add 1 in all odd values and 2 in all even values of the list L.
Example: If original elements of the list L are:
L= [35, 12, 16, 69, 26]
The modified list will be: L= [36, 14, 18, 70, 28]
23. Write a function DIVI_LIST() where NUM_LST is a list of numbers passed as argument to the function. The
function returns two list D_2 and D_5 which stores the numbers that are divisible by 2 and 5 respectively from the
NUM_LST. Example:
NUM_LST=[2,4,6,10,15,12,20]
D_2=[2,4,6,10,12,20]
D_5=[10,15,20]
24. Vishnu is a Python programmer. He has written a code and created a binary file record.dat withstudentid,
subjectcode and marks. The file contains 10 records. He now has to update a record based on the studentid id
entered by the user and update the marks. The updated record is then to be written in the file temp.dat. The records
which are not to be updated also have to be written to the file temp.dat. If the student id is not found, an appropriate
message should to be displayed.
As a Python expert, help him to complete the following code based on the requirement givenabove:
import #Statement 1
def update_data():
rec={}
fin=open("record.dat","rb")
fout=open(" ") #Statement 2
found=False
sid=int(input("Enter student id to update his marks :: "))
while True:
try:
rec = #Statement 3
if rec["studentid"]==sid:
found=True
rec["marks"]=int(input("Enter new marks :: "))
pickle. #Statement 4
else:
pickle.dump(rec,fout)
except:
break
if found==True:
print ("The marks of studentid ", sid ," has been updated.")
else:
print("No student with such id is not found")fin.close()
fout.close()

(i) Which module should be imported in the program? (Statement 1)


(ii) Write the correct statement required to open a temporary file named temp.dat. (Statement 2)
Which statement should Aryan fill in Statement 3 to read the data from the binary file, record.dat and in
Statement 4 to write the updated data in the file, temp.dat?
25. Star Info Solution is a professional consultancy company. The company is planning to set up their
new offices in India with its hub at Jaipur. As a network adviser, you have to understand their requirement
and suggest them the best available solutions. Their queries are mentioned as (i) to (iv) below.
Physical Locations of the blocked of Company

26. Alka Institute is planning to set up its centre in Bikaner with four specialized blocks for Medicine,
Management, Law courses along with an Admission block in separate buildings. The physical distances
between these blocks and the number of computers to be installed in these blocks are given below. You as a
network expert have to answer the queries raised by their board of directors as given in (i) to (iv).

Distances between various locations in meters: Number of Computers installed at various locations:

(i). Suggest the most suitable location to install the main server of this institution to get efficient
connectivity.
(ii). Suggest by drawing the best cable layout for effective network connectivity of blocks having server
with all the other blocks.
(iii). Suggest the devices to be installed in each of these buildings for connecting computers installed within
the building out of the following:
• Modem • Switch • Gateway • Router
(iv). Suggest the most suitable wired medium for efficiently connecting each computer installed in every
building out of the following network cables:
Coaxial Cable Ethernet Cable Single Pair Telephone Cable
27. National Centre for Indigenous Arts has its Headquarter in Dehi and just set up a new Campus in Kolkata.
They want to set up a Local area network in Kolkata campus. The Campus has four buildings:
● Main Building ● Admin ● Finance ● Academic
The distances between various buildings of university are given as:-

28. Consider the following table HOSPITAL. Answer the questions that follows the table:

You might also like