Uploaded by swastisingh290107

COMPUTER HH

advertisement
CLASS : 12
SUBJECT : COMPUTER SCIENCE
TOPICS :
1.
2.
3.
REVISION TOUR I
RERVISION TOUR II
WORLING WITH
FUNCTIONS
SUMMER HOLIDAY
HOMEWORK
2023
SUBJECT TEACHERS :
1.
2.
3.
MS. ANJALI SHARMA
MS. SHWETA GUPTA
MR. YUSUF
HOLIDAY HOMEWORK
CLASS - XII
SUBJECT - COMPUTER SCIENCE
Topic - Revision Tour( I, II )
MULTIPLE CHOICE QUESTIONS[1] Find the invalid identifier from the following:
a) MyName
b) True
c) 2ndName
d) My_Name
[2] Given the lists L=[1,3,6,82,5,7,11,92] , write the output of print(L[2:5]).
[3] Identify the valid arithmetic operator in Python from the following.
a) ?
b) <
c) **
d) and
[4] Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect?
a) print(T[1])
b) T[2] = -29
c) print(max(T))
d) print(len(T))
[5] Write a statement in Python to declare a dictionary whose keys are 1, 2, 3 and values are Monday, Tuesday and
Wednesday respectively.
[6] A tuple is declared as T = (2,5,6,9,8) What will be the value of sum(T)?
[7] If the following code is executed, what will be the output of the following code?
name="ComputerSciencewithPython"
print(name[3:10])
[8] Find the invalid identifier from the following:
a. none
b. address
c. Name
d. pass
[9] Consider a declaration L = (1, ‘Python’, ‘3.14’). Which of the following represents the data type of L?
a. list
b. tuple
c. dictionary
d. string
[10] Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90). What will be the output of print (tup1 [3:7:2])?
a. (40,50,60,70,80)
b. (40,50,60,70)
c. [40,60]
d. (40,60)
[11] Which of the following operator cannot be used with string data type?
a. +
b. in
c. *
d. /
[12] Consider a tuple tup1 = (10, 15, 25, and 30). Identify the statement that will result in an error.
a. print(tup1[2])
b. tup1[2] = 20
c. print(min(tup1))
d. print(len(tup1)
[13] Which one of the following is the default extension of a Python file?
a. .exe
b. .p++
c. .py
d. .p
[14] Which of the following symbol is used in Python for single-line comment?
a. /
b. /*
c. //
d. #
[15] Which of these about a dictionary is false?
a) The values of a dictionary can be accessed using keys
b) The keys of a dictionary can be accessed using values
c) Dictionaries aren’t ordered
d) Dictionaries are mutable
[16] What is the output of the following code:
T=(100)
print(T*2)
a. Syntax error
b. (200,)
c. 200
d. (100,100)
[17] Identify the output of the following Python statements.
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)
a. 12.0
b. 13.0
c. 14.0
d. 15.0
[18] Identify the output of the following Python statements.
x=2
while x < 9:
print(x, end='')
x=x+1
a. 12345678
b. 123456789
c. 2345678
d. 23456789
[19] Identify the output of the following Python statements.
b=1
for a in range(1, 10, 2):
b += a + 2
print(b)
a. 31
b. 33
c. 36
d. 39
[20] Identify the output of the following Python statements.
lst1 = [10, 15, 20, 25, 30]
lst1.insert( 3, 4)
lst1.insert( 2, 3)
print (lst1[-5])
a. 2
b. 3
c. 4
d. 20
21] Evaluate the following expression and identify the correct answer.
16 – (4 + 2) * 5 + 2**3 * 4
a. 54
b. 46
c. 18
d. 32
[22] State True or False “A python function may return multiple values."
[23] Which of the following is an invalid datatype in Python?
(a) Set
(b) None
(c) Integer
(d) Real
[24] Given the following dictionaries :
dict_exam={"Exam":"AISSCE", "Year":2023}
dict_result={"Total":500, "Pass_Marks":165}
Which statement will merge the contents of both dictionaries?
a. dict_exam.update(dict_result)
b. dict_exam + dict_result
c. dict_exam.add(dict_result)
d. dict_exam.merge(dict_result)
[25] Consider the given expression:
not True and False or True
Which of the following will be the correct output if the given expression is evaluated?
(a) True
(b) False
(c) NONE
(d) NULL
[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] Which of the following statement(s) would give an error after executing the following code?
S="Welcome to class XII" # Statement 1
print(S) # Statement 2
S="Thank you" # Statement 3
S[0]= '@' # Statement 4
S=S+"Thank you" # Statement 5
(a) Statement 3
(b) Statement 4
(c) Statement 5
(d) Statement 4 and 5
[28] 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
[29] Which value type does input() return?
(a) Boolean
(b) String
(c) Int
(d) Float
[30] Which is the correct form of declaration of dictionary?
a. Day={1:’monday’,2:’tuesday’,3:’wednesday’}
b. Day=(1;’monday’,2;’tuesday’,3;’wednesday’)
c. Day=[1:’monday’,2:’tuesday’,3:’wednesday’]
d. Day={1’monday’,2’tuesday’,3’wednesday’]
[31] Kunj has declared a variable as follows:
L=[1,45,’hello’,54.6]
Identify L?
a. List
b. Tuple
c. Dictionary
d. Function
[32] Write the output of following:
x = "abcdef"
i = "a"
while i in x:
print(i, end = " ")
a. abcdef
b. abcde
c. bcde
d. infinite loop
[33] Observe the following code written by Rupal. She has used ++ in place of the exponential operator. Rewrite the
correct code after removing all errors.
r=3.5,h=2.5
area=2*pi*r*h+2*(r++2)
print (area)
Which of the following operator will replace ++?
a. //
b. *
c. **
d. %
[34] The keys of a dictionary must be of _____ types.
(a) Integer
(b) mutable
(c) immutable
(d) any of these
[35] Write the output of the code given below:
my_dict = {"name": "Aman", "age": 26}
my_dict['age'] = 27
my_dict['address'] = "Delhi"
print(my_dict.items())
a. dict_items([(‘name’, ‘Aman’), (‘age’, 27), (‘address’, ‘Delhi’)])
b. dict_items([(‘name’,’Aman’),(‘age’,26)])
c. dict_items({name:’Aman’,age:27,’address’:’Delhi’})
d. Error Message
[36] For the given declaration in Python as s=’WELCOME’:
Which of the following will be the correct output of print(S[1::2])?
a) WEL
b) COME
c) WLOE
d) ECM
[37] Which of the following is the correct output for the execution of the following Python statement?
print (5 + 3 ** 2 /2)
a) 82
b) 9.5
c) 8.0
d) 32.0
[38] Which of the following is not a Tuple in Python?
a) (1,2,3)
b) (“One”,”Two”, “Three”)
c) (10,)
d) (“one”)
[39] Which of the following is not a valid Python string operation?
a) ‘Welcome’ + ’10’
b) Welcome’ * 10
c) ‘Welcome’ * 10.0
d) “10” + ‘Welcome”
[40] What will be the output for the following Python statements?
L =[10, 20, 30, 40, 50]
L=L+5
print (L)
a) [10, 20, 30, 40, 50, 5]
b) [15, 25, 35, 45,55]
c) [5,10, 20, 30, 40, 50]
d) Error
[41] You have the following code segment:
String1 = "my"
String2 = "work"
print(String1 + string2)
What is the output of this code?
(a) my work
(b) work
(c) mywork
(d) my
[42] Which is the correct form of declaration of dictionary?
(a) Day = {1 : 'Monday', 2 : 'Tuesday', 3 : 'wednesday'}
(b) Day = {1 ; 'Monday', 2 ; 'Tuesday', 3 ; 'wednesday'}
(c) Day = [1 : 'Monday', 2 : 'Tuesday', 3 : 'wednesday']
(d) Day = {1 'Monday', 2 'Tuesday', 3 'wednesday'}
[43] Which amongst the following is a mutable data type in Python?
(a) int
(b) string
(c) tuple
(d) list
[44] Which of the following is correct statement to computer square of variable x in python?
(a) x * 2
(b) x power 2
( c ) x ** 2
(d) x // 2
[45] To add a new element to a list we use which command ?
a) list1.add(5)
b) list1.append(5)
c) list1.addLast(5)
d) list1.addEnd(5)
[46] Following set of commands is executed in shell, what will be the output?
>>>str = "hello"
>>>str[ : 2]
>>>
(a) he
(b) lo
(c) olleh
(d) hello
[47] Which of the following expressions results in an error?
(a) float('12')
(b) int('12')
(c) float('12.5')
(d) int('12.5')
[48] What will be the output of the following Python code ?
L = [10, 201]
L1=[30,40]
L2=[50,60]
L.append (L1)
L.extend (L2)
print (L)
a) [60, 50, 40, 30, 20, 10]
b) [10, 20, 30, 40, 50, 60]
c) [10, 20, 30, 40, [50, 60]]
d) [10, 20, [30, 40], 50, 60]
[49] Which of the following is an invalid variable?
(a) my_day_2
(b) 2nd_day
(c)Day_two
(d) _2
[50] What will be the value of the expression?
14 +13 % 15
(a) 14
(b) 27
(c) 12
(d) 0
Topic - Working with Functions
1. A function in python begins with which keyword?
a) void
b) return
c) int
d) Def
2. Which of the following items are present in the function header?
a) function name
b) parameter list
c) return value
d) Both a and b
3. What is called when a function is defined inside a class?
a) class
b) function
c) method
d) module
4. If return statement is not used inside the function, the function will return:
a) None
b) 0
c) Null
d) Arbitary value
5. What is a recursive function?
a) A function that calls other function.
b) A function which calls itself.
c) Both a and b
d) None of the above
6. Which of the following is the use of id() function in python?
a) Id() returns the size of object.
b) Id() returns the identity of the object.
c) Both A and B
d) None of the above
7. Which of the following function headers is correct?
a) def fun(a = 2, b = 3, c)
b) def fun(a = 2, b, c = 3)
c) def fun(a, b = 2, c = 3)
d) def fun(a, b, c = 3, d)
8. In which part of memory does the system stores the parameter and local variables of function call?
a) heap
b) stack
c) Uninitialized data segment
d) None of the above
9. How is a function declared in Python?
a) def function function_name():
b) declare function function_name():
c) def function_name():
d) declare function_name():
10. Which one of the following is the correct way of calling a function?
a) function_name()
b) call function_name()
c) ret function_name()
d) function function_name()
11. You can also create your own functions, these functions are called?
a) built-in functions
b) user-defined functions
c) py function
d) None of the above
12. ___________ are the arguments passed to a function in correct positional order.
a) Required arguments
b) Keyword arguments
c) Default arguments
d) Variable-length arguments
13. Which of the following will print the pi value defined in math module?
a) print(pi)
b) print(math.pi)
c) from math import pi
print(pi)
d) from math import pi
print(math.pi)
14. What is a variable defined outside a function referred to as?
a) local variable
b) global variable
c) static Variable
d) automatic variable
15. Which one of the following is incorrect?
a) The variables used inside function are called local variables.
b) The local variables of a particular function can be used inside other functions, but these cannot be used in global
space
c) The variables used outside function are called global variables
d) In order to change the value of global variable inside function, keyword global is used.
16. Name the statement that sends back a value from a function
a) print
b) input
c) return
d) None
17.What is the output of the program given below:
x=50
def func(x):
x=2
func(x)
print(‘x is now’,x)
a) x is now 50
b) x is now 2
c) x is now 100
d) Error
18. What is the output of the program given below:
def cal(a,b,c):
return a*3,b*3,c*3
val=cal(10,12,14)
print(val)
a) [30, 24, 28]
b) [30,36,42]
c) [10, 20, 30]
d) [10,12,14]
19.What is the output of the expression: round(4.576)
a) 4.5
b) 5
c) 4
d) 4.6
20.What is the output of the function shown below?
import math
abs(math.sqrt(25))
a) Error
b) -5
c) 5
d) 5.0
21.How many keyword arguments can be passed to a function in a single function call?
a) zero
b) one
c) zero or more
d) one or more
22. What is returned by
>>> math.ceil(3.4)?
a) 3
b) 4
c) 4.0
d) 3.0
23. What is the value returned by
>>> math.floor(3.4)
a) 3
b) 4
c) 4.0
d) 3.0
24.What is output of print(math.pow(3, 2))?
a) 9
b) 9.0
c) None
d) None of these
25.What will be the output of the following code:
A=1
def f ():
A=10
print(A)
a) 1
b) 10
c) Error
d) None
26. def Interest(p,c,t=2,r=0.09):
return p*t*r
Considering the above defined function which of following function call are legal.
1) Interest(p=1000,c=5)
2) Interest(r=0.05,5000,3)
3) Interest(500,t=2,r=0.05)
4) Interest(c=4,r=0.12,p=5000)
a) 1 , 2 and 4
b) 2 & 3
c) 1 &4
d) 3 & 4
27. The function can be called in the program by writing function name followed by ____
a) [ ]
b) { }
c) ( )
d) None of the above
28. Aman wants to write a function in python. But he doesn’t know how to start with it! Select the keyword used to
start a function out of the following:
a) function
b) start
c) def
d) fun
29.Which of the following is not a part of the python function?
a) function header
b) return statement
c) parameter list
d) function keyword
30. Pranjal wants to write a function to compute the square of a given number. But he missed one statement in the
function. Select the statement for the following code:
def sq(n):
____________
print(sq(3))
a) return square of n
b) return n**2
c) return n
d) print(“n**n”)
31. Which of the following function header is correct :
a) def discount(rate=7,qty,dis=5)
b) def discount(rate=7,qty,dis)
c) def discount(rate,qty,dis=5)
d) def discount(qty,rate=7,dis)
32. What will be the output of the following code?
def fun(x=10, y=20):
x+=5
y=y-3
return x*y
print(fun(5),fun())
a) 20, 200
b) 170, 255
c) 85, 200
d) 300, 500
33. Name the statement that sends back a value from a function.
(a) print
(b) input
(c) return
(d) None
34. Functions that do not return any value are known as:
(a) fruitful functions
(b) void functions
(c) library functions
(d) user-defined functions
35.What is the output of the program given below?
x = 50
def func (x) :
x=2
func (x)
print ('x is now', x)
(a) x is now 50
(b) x is now 2
(c) x is now 100
(d) Error
36. What is the result of this code?
def print_double(x):
print(2 ** x)
print_double(3)
(a) 8
(b) 6
(c) 4
(d) 10
37. Which of the given argument types can be skipped from a function call?
(a) positional arguments
(b) keyword arguments
(c) named arguments
(d) default arguments
38. What is the output of the below program?
def printMax(a, b):
if a > b:
print(a, ‘is maximum’)
elif a == b:
print(a, ‘is equal to’, b)
else:
print(b, ‘is maximum’)
printMax(3, 4)
a) 3
b) 4
c) 4 is maximum
d) None of the mentioned
39. What is the output of the below program?
def sayHello():
print('Hello World!')
sayHello()
sayHello()
a)
Hello World!
Hello World!
b)
‘Hello World!’
‘Hello World!’
c)
Hello
Hello
d) None of the mentioned
40. What is the output of the below program?
def C2F(c):
return c * 9/5 + 32
print (C2F(100))
print (C2F(0))
a) 212.0
32.0
b) 314.0
24.0
c) 567.0
98.0
d) None of the mentioned
41. What is the output of the following piece of code?
def a(b):
b.append(5)
c = [1, 2, 3, 4]
a(c)
print(len(c))
a)4
b)5
c)1
d)An exception is thrown
42. What is the output of the following code?
a=10
b=20
def change():
global b
a=45
b=56
change()
print(a)
print(b)
a)10
56
b)45
56
c)10
20
d)Syntax Error
43. What is the output of the following code?
def change(i = 1, j = 2):
i=i+j
j=j+1
print(i, j)
change(j = 1, i = 2)
a)An exception is thrown because of conflicting values
b)1 2
c)3 3
d)3 2
44. What will be the output of the following Python code -
def cube(x):
return x * x * x
x = cube(3)
print x
a) 9
b) 3
c) 27
d) 30
45. What will be the output of the following Python code x=20
def fun():
x=10
print(x)
fun()
print(x)
a)10
20
b)20
10
c)10
10
d)Syntax Error
46. What are the errors in following codes? Correct the code and predict output:
total = 0 ;
def sum( arg1, arg2 ):
total = arg1 + arg2 ;
print("Total :", total)
return total ;
sum( 10, 20 ) ;
print("Total :", total)
47. What will be the output of following programs?
num = 1
def myfunc ():
return num
print(num)
print(myfunc())
print(num)
48. In the following code, which variables are in the same scope?
def func1():
a=1
b=2
def func2():
c=3
e=5
a) a
b) b
c) a, b and c
d) e
49. True or False
The variable declared inside a function is
called a global variable.
True or False
50. The first line of a function header begins with
def keyword and eventually ends with a colon :
Related documents
Download