Xii Computer Assignment (2023-24)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

VIDYA MANDIR PUBLIC SCHOOL

Class XII
COMPUTER SCIENCE
ASSIGNMENT

GENERAL INSTRUCTIONS:
• Holidays Homework must be done in a very neat and presentable
manner.
• Submission of Holidays Homework post vacation is compulsory
for all the students.
Revision of Python Topic
1) T=1,2,3
(a) Tuple (b) List (c) variable (d) None of these
2) Evaluate the following expression
Not 20>21 and 6>5 or 7>9
(a) True (b) False (c) 3 (d) None of these
3) What will the following expression be evaluated to in Python?
print(15.0 / 4 + (8 + 3.0))
(a) 14.75 (b)14.0 (c) 15 (d) 15.5
4) Which is valid keyword?
(a) Int (b) WHILE (c) While (d) if
5) Which of the following is not a valid identifier name in Python?
(a) 5Total (b) _Radius (c) pie (d) While
6) Consider the following expression:
51+4-3**3//19-3
Which of the following will be the correct output if the expression is evaluated?
7) What will the following expression be evaluated to in Python?
10*1*2**4-4//4
8) What is the output of the expression 3*1**3?
9) What is the output of the expression 3**1**3?
10) Find and write the output of the following:
x="abcdef"
i="a"
while (i in x):
print( i, end=” “)

11) How many times will the following for loop execute and what’s the output?
(i) for i in range(-1,7,-2):
for j in range(3):
print(1,j)

(ii) for i in range(1,3,1):


for j in range(i+1):
print(‘*’)

12) What are data types? What are Python’s built in core data types?
13) What are immutable and mutable types? List immutable and mutable types of Python.
14) What is the difference between implicit and explicit type conversion?
15) What is entry controlled loop? Which loop is entry controlled loop in Python?
16) What are the two ways to add something to a list? How are they different?
17) What are the two ways of removing something from a list? How are they different?
18) What is the difference between (30) and (30,)?
19) How is del(D) and del (D[<key>]) different from one another if D is a dictionary?
20) Name the function/method required to:
a) Check if a string contains only lowercase letters
b) Check if a string contains only digits
c) Check if a string contains only spaces

21) Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code.
25=Val 30=To STRING ="WELCOME"
for i in the range(0,Val) for K in range(0,To) NOTE=""
if i %2=0: IF k%5==0: for st in range[0,8]:
Print(i +1) print (K*4) print(STRING(S))
Else: Else: print(S STRING)
print (i -1) print (K+3)
(a) (b) (C)

22) What will be the output of the following Python code snippet?
X=11
If X<=10:
X+=10
if X<=20 :
X+=10
If X<=30:
X+=30

(a)21 (b) 31 (c) 61 (d) None of these

23) What will be the output of the following statement given:


txt="cbse. sample paper 2022"
print(txt.capitalize())

24) Give output


RS=''
S="important"
for i in S:
RS=i+RS
print(RS)
25) What will be the output of the following Python code snippet?

x = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]


result = []
for items in x:
for item in items:
if item % 2 == 0:
result.append(item)
print(result)

26) Select the correct output of the code:


a = "Year 2022 at All the best"
a = a.split('2')
b = a[0] + ". " + a[1] + ". " + a[3]
print (b)

(a) Year . 0. at All the best (b) Year 0. at All the best
(c) Year . 022. at All the best (d) Year . 0. at all the best

27) Select the correct output of the code:


Str=“Computer”
Str=Str[-4:]
print(Str*2)

28) Convert the following for loop into while loop”


for k in range(11,30,5) : for k in range (200,250) :
print(k) if ( k%2==0):
print(“Even No”)
else:
print(“Odd N0”)
(a) (b)

29) WAP to print the index of the character in a string.


30) Write a program to find the second largest number of a list of numbers.
31) Write a program to input two lists and display the maximum element from the
elements of both the lists combined, along with its index in its list.
32) WAP that prompt the user to type some sentence(s) followed by “enter”. It should
then print the original sentence(s) and the following statistics relating to the
sentence(s):
(a) Number of characters (b) Number of spaces: (c) Number of words:
FUNCTION
1) The values being passed through a function call statements are called
a) Actual parameter b) Formal parameter
c) default parameter d) None of these
2) Assertion (A): Global variable is declared outside the all the functions.
Reasoning (R): It is accessible through out all the functions.
3) What is a module?
4) Name some of the built-in modules in Python.
5) Which of the keywords marks the beginning of the function block?
6) What is the difference between the formal parameters and actual parameters?
7) Differentiate between built-function and functions defined in modules.
8) Find the errors in the following function definitions:
(a) (b)
def extract1(L,v): def tot(number):
for num in L: sum=0
if : for c in Range(1,number+1)
List1.append(num) sum+=c
return (List1) Return sum
print(tot[3])
print(tot[6])

9) For the given 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 (i) to (iv). Also find the least 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

10) Rewrite the following Python code after removing all syntax error(s). underline the
corrections done.
def main() :
r = input ( ‘ enter any radius: ‘)
A – pi * maths.pow (r,2)
Print (“Area = “ +a)
Main()
11) Give output:
def max_of_two( x, y ):
if x > y:
return x
else
return y
def max_of_three( x, y, z ):
return max_of_two( x, max_of_two( y, z ) )
print(max_of_three(3, 6, -5))

(a) 3 (b) 6 (c) -5 (d) error

12) Give output of the following code


def func(a, b=5, c=10):
print('a is', a, 'and b is', b, 'and c is', c)
func(3, 7)
func(25, c = 24)
func(c = 50, a = 100)

13) Find out the output :


a=10
def call():
global a
b=20
a=a+b
print(a)
call( )

(a) 10 (b) 30 (c) error (d) 20

14) Study the following program and select the possible output(s) and write maximum
and minimum value assigned to the variable y

import random
x=random.random( )
y=random.ranint(0,4)
print((int(x),":",y+int(x)))

(i) 0:0 (ii) 1: 6 (iii) 2:4 (iv) 0:3


15) Give output of the following program :
def div5(n):
if n%5==0:
return n*5
else:
return n+5
def output(m=5):
for i in range(0,m):
print(div5(i),'@',end=" ")
print('\n')
output(7)
output()
output(3)

16) Predict the output of the following code:


def CALLME(n1=1,n2=2):
n1=n1*n2
n2+=2
print(n1,n2)
CALLME()
CALLME(3)

17) Find and write the output of the following python code:
def Call(P=40,Q=20):
P=P+Q
Q=P–Q
print(P,'@',Q)
return P
R=200
S=100
R=Call(R,S)
print (R,'@',S)
S=Call(S)
print(R,'@',S)
18) Write the output of following python code:

def result(s):
n = len(s)
m=''
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m + s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m + s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m + '#'
print(m)
result('Cricket')

19) Write a method/function COUNTLINES_ET() in python to read a string and COUNT the
number of ‘E’ or ‘e’ and
Number of 'T' and 't' display the Total count separately.
20) Write a method/ function SHOW_TODO() in python to read a string and COUNT the
number of words "TO" and "DO" and display the total count separately.
21) Python funtion oddeve(L) to print positive numbers in a list L.
Example: Input: [4, -1, 5, 9, -6, 2, -9, 8]
Output: [4, 5, 9, 2, 8]
20) Write definition of a Method COUNTROW(REGIONS) to find and display names of
those REGIONS, in which there are less than or equal to 5 characters.
For example :
If the list REGIONS contains ["GOA","NEW DELHI", "DAMAN", "CHENNAI", "BANGALORE"]
The following should get displayed
GOA
DAMAN

You might also like