0% found this document useful (0 votes)
124 views9 pages

Cs HHW

The document contains instructions for students to write the output of various Python code snippets. There are 14 code snippets provided along with multiple choice options for the expected output of some snippets. Students are asked to write their responses on paper and submit their answers. They are also provided with a practical file section where they need to write 10 Python programs related to files, databases, and data structures along with the output of each program. Finally, there is a project section where students need to work in groups to create a useful real-world application using Python and SQL.

Uploaded by

Aditya Jyoti
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)
124 views9 pages

Cs HHW

The document contains instructions for students to write the output of various Python code snippets. There are 14 code snippets provided along with multiple choice options for the expected output of some snippets. Students are asked to write their responses on paper and submit their answers. They are also provided with a practical file section where they need to write 10 Python programs related to files, databases, and data structures along with the output of each program. Finally, there is a project section where students need to work in groups to create a useful real-world application using Python and SQL.

Uploaded by

Aditya Jyoti
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/ 9

Navy Children School

Holiday Homework
Computer Science
Class – XII
Instructions:
Write the answers on A4 size paper or loose Register sheets
1. What will be the output of the following python program?
def display:
print(“program”)
def main():
print(“This is python”)
display();
main()
2. What will be the output of the following python program?
def add(j):
if(j>=4):
j = j*j
return j
else:
j= j*2;
return j
def main():
i=4
a=add(4)
print(“The value of a is: %d” %a)
main()
3. What will be the output of the following python program?
i = 100
def abc():
i=8
print(“First = %d” %(i))
def main():

1
i=2
abc()
print(“Second = %d” %(i))
main()

4. What will be the output of the following python program?


def sum_list (list):
for i in list:
sum = i
return sum
def main():
list = [45,2,10,-5,100]
print(sum_list(list))
main()
5. What is the output of the following code?
a=1
def f():
a = 10
print(a)
6. What will be the output of the following code?
def interest (prnc, time = 2, rate = 0.10):
return (prnc*time*rate)
print(interest (6100, 1))
print(interest (5000, rate = 0.05))
print(interest (5000, 3, 0.12))
print(interest (time = 4, prnc = 5000))

7. Carefully observe the following python code and answer the questions
that follow:
x=5
def fun2():
x=3
global x
x = x+1
print x

2
print x
On execution the above code produces the following output
6
3
8. Consider the following code :
import random
print (int (20+random.random( ) * 5),end= ‘ ‘)
print (int (20+random.random( ) * 5),end= ‘ ‘)
print (int (20+random.random( ) * 5),end= ‘ ‘)
print (int (20+random.random( ) * 5))

Find the suggested output from options (i) to (iv) . Also write the least
value and highest value that can be generated.
(i) 20 22 24 25 (ii) 22 23 24 25 (iii) 23 24 23 24 (iv) 21 21 21 21
9. Observe the following python code and find out which out of the given
options (i) to (iv) are the expected outputs. Also assign the maximum
and minimum value that can be assigned to the variable ‘Go’
import random
X = [100,75,10,125]
Go = random.randint(0,3)
for i in range(Go):
print(X[i], “$$”, end = “”)
(i) 100 $$75 $$10
(ii) 75$$10$$125$$
(iii) 75$$10$$
(iv) 0$$125$$100
10.Observe the following program and answer the questions that follow:
import random
X=3
N = random.randint(1,X)
for i in range(N):
print(i, ‘#’, i+1)
(a) What is the maximum and minimum number of times the loop will
execute?
(b) Find out which line of outputs out of (i) to (iv) will not be executed
from the program
(i) 0#1

3
(ii) 1#2
(iii) 2#3
(iv) 3#4
11.Rewrite the following code in python after removing all syntax errors.
Underline each correction done in the code
Val = int(input(“Value:”))
Adder = 0
for C in range(1,Val,3):
Adder += C
if C%2=0:
print(C*10)
Else:
print(C*)
print Adder
12.Rewrite the following code after removing the syntactical errors (if any).
Underline each correction
def chksum:
x = input(“Enter a number:”)
if (x%2 = 0):
for i range(2*x):
print i
loop else:
print “#”
13.Correct the following code:
def count_to_ten():
for i in range[10]:
print(i)
count_to_ten()

14.Find out the error in the following program and write the correct line of
code:
def sum(arg1,arg2):
total = arg1+arg2;
print(“Inside the function local total:”,total)
return total;
def main():
n1 = int(input(“First value is:”))

4
n2 = int(input(“Second value is:”))
sum(n1)
print(“The sum is:”,total)
main()

15.From the program code given below, identify the parts mentioned
below:
def processNumbers(x):
x = 72
return x+3
y = 54
res = processNumber(y)
Identify these parts: function header, function call, arguments, parameters,
function body, main program

Practical File
Write the following programs and their outputs in the practical file:
1 Program to get roll numbers, names and marks of the students of a class from user
and store these details in a file called “Marks.txt”

2 Program to read a text file line by line and display each word separated by a ‘#’.

3 Program to read a text file and display the number of vowels/ consonants/
uppercase/ lowercase characters in the file.

4 Program to get student roll no., name and marks from user and write onto a binary
file.
5 Program to append student record to a binary file by getting data from user.

6 Program to create a binary file with name and roll number. Search for a given roll
number and display the name, if not found display appropriate message.

7 Program to create a binary file Stu.dat storing student details and update the
records of the file so that those who have scored more than 81 marks, get additional
bonus of 2 marks

8 Program to create a binary file with roll number, name and marks. Input a roll
number and update the marks.

9 Program to remove all the lines that contain the character `a' in a file and write it
to another file.

5
10 A binary file “STUDENT.DAT” has structure (admission_number, name ,
percentage).Write a function CountRec( ) in Python that would read contents of the
file “STUDENT.DAT” and display the details of those students whose percentage is
above 75. Also display number of students scoring above 75%.

11 Write a random number generator that generates random numbers

12 Program to implement a stack using a list data-structure.

13 Program to create CSV file to store student rollno, name, marks

14 Program to read the records of CSV file and display.

15 Program to modify CSV file so that blank lines for EOL character are not
displayed.

16Take a sample of any text file and find most commonly occurring word(s)

17 Program to insert record into a MySQL database.

18 Program to update record in a MySQL database.


19 Program to delete a record from a MySQL database .

20 Program to display all records from a MySQL database.

Project
The aim of the class project is to create something that is tangible and useful
using Python / Python and SQL connectivity. This should be done in groups of two
or three students . The aim here is to find a real world problem that is worthwhile to
solve.
For example, if a business is finding it hard to create invoices for filing GST claims,
then you can do a project that takes the raw data (list of transactions), groups the
transactions by category, accounts for the GST tax rates, and creates invoices in the
appropriate format. You can be extremely creative here. You can use a wide
variety of Python libraries to create user friendly applications. Save the project file
with .py extension

6
Activities
1. Create a calculator using Python coding syntax.
2. Write Python code to create Tic Tac Toe game
3. Create alarm clock using Python coding technique

11 Program to implement insertion and deletion of elements in a queue using a list


data-structure

PROGRAM-11
q=[]
c="y"
while c=="y":
print("1.Insert")
print("2.Delete")
print("2.Display")
choice=int(input("Enter your choice:"))
if choice==1:
a=input("Enter any number:")
q.append(a)
elif choice==2:
if q==[]:
print("Queue Empty")
else:
print("Deleted element is:",q.pop(0))
elif choice==3:
l=len(q)
for i in range(0,l):
print(q[i])
else:

7
print("Wrong input")
c=input("Do you want to continue or not?")

output-
1.Insert
2.Delete
2.Display
Enter your choice:1
Enter any number:1
Do you want to continue or not?y
1.Insert
2.Delete
2.Display
Enter your choice:1
Enter any number:2
Do you want to continue or not?y
1.Insert
2.Delete
2.Display
Enter your choice:1
Enter any number:3
Do you want to continue or not?y
1.Insert
2.Delete
2.Display
Enter your choice:2
Deleted element is: 1
Do you want to continue or not?y

8
1.Insert
2.Delete
2.Display
Enter your choice:3
2
3
Do you want to continue or not?n

1. What is the output of the following code fragment?


d={0:’a’,1:’b’,2:’c’}
for x in d.values( ) :
print(x, end=’ ‘)

You might also like