Question Bank Subject: Computer Science: Class: XII Sub. Code: 083

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

QUESTION BANK

SUBJECT : COMPUTER SCIENCE


Class: XII Sub. Code: 083

CHAPTERS
Python Revision Tour

1. Find the invalid identifier from the following


a) def b) For c)_bonus d)First_Name

2. Find and write the output of the following python code:


x = "Python"
print(x[ : :-1])
print(x)
a) ythpo b) nohtyP c)Python d)nohtPy

3. Evaluate the following expressions:


not(20>6) or (19>7) and (20==20)
a) True b) False c) Both d)None

4. Give the output:


for i in range(1,10,3):
print(i,sep=”-”,end=”*”)
a) 1-4-7* b) 1-4-7-10* c) 1*4*7* d) 1*4*7*10

5. If the following code is executed, what will be the output of the following code?
name=”ComputerSciencewithPython”
print(name[3:10])
a) mputerS   b) puterSc   c) mputerScie   d) puterScien
6. m = 16
m = m+1
if m<15:
print(m)
else:
print(m+15)
a) 32   b) 16   c) 17   d) 31

7. Write the value that will be stored in variable t after the execution of the
following code. How many times will the loop execute?
sum = score = 0
while score <=3:
score = score +1
sum = sum + score
t = sum // 3
print(t)
1
a) Value of t will be 4 Loop executes 3 times
b) Value of t will be 3 Loop executes 4 times
c) Value of t will be 3 Loop executes 3 times
d) Value of t will be 4 Loop executes 4 times

8. Which of the following is not a Python legal string operation?


a) ‘xyz’ + ‘xyz’ b)’xyz’ * 3 c) ‘xyz’ + 3 d)’xyz’.lower()

9. Consider the statement:


first_name = “Ayana”
What is the datatype of first_name ?
a)integer b)Boolean c)float d)string
10. Is 456 the same as “456” ?
a)yes b)maybe c)no d)none of the options

11. Write the value that will be assigned to variable x after executing the following
statement:
x = 3 + 36/12 + 2*5
a)4 b)25 c)16 d)16.0

12. Evaluate the following expressions:


10 > 5 and 7 > 12 or not 18 > 3
a)True b)False c)Not Possible d)Both a and b

13. Give the output


print(40,50,60,sep=”*“,end=”!”)
a) 40*50*60! b) 40!50!60! c) 40!50!60* d) 40*50*60

14. Give the output if a=10 and b=20


a=input(“enter no”)
b=input(“enter 2nd no”)
print(a+b)

a)20 b)30 c)1020 d)2010


15. What will be the output of below Python code?
Str1 = ’power’
Str2 = Str1.upper()
print(Str2)

a)POWER b)Power c)power d)poWer

16. Give the output


a=5
b=20
a+=b
b-=a
print(a,b)

a) 25,15 b) 25,5 c) 25,-5 d) 25,25


2
17. Give the output
a=16
b=3
c=a/2**b
print(c)

a) 512.0 b) 4.0 c) 2.0 d) 24.0

18. Which of the following expressions results in an error?


a) float(‘12’) b) int(‘12’) c) float(‘12.5’) d) int(‘12.5’)

19. What will be the output of the following


14.0 % 4

a) 2 b) 2.0 c) 20 d) 3

20. What abandons the current iteration of the loop


a) continue b) stop c) infinite d) Break

21. What will be the output of the following Python code?


Word1 = ‘Application’
Word2 = Word1.replace(‘a’,’A’)
print(Word2)
a) application b) Application c) ApplicAtion d) applicAtion

22. What is the output of the following?


x = 123
for i in x:
print(i)
a) 1 2 3 b) 123 c) error d) none of the
mentioned

23. What is the output of the following?


x = 'abcd'
for i in range(len(x)):
print(x,end=’ ‘)
x = 'a'
a) a b) abcd abcd abcd abcd c) a a a a d) abcd a a a

3
24. Give the output
for i in range(1,5):
print(i * i,end=’ ‘)
a) 1 2 3 4 5 b) 1 4 9 16 c) 1 9 4 16 d) 5 4 3 2 1

25. Write the value that will be stored in variable sum after execution of following
code?
sum=0
for i in range(9,5,-1):
if(i%3==0):
sum = sum + i
else:
sum = sum - i
print(i,sum)
a) 0 9 b) 6 0 c) 0 6 d) 9 0

26. Which of the following is a mutable type.


a) string b) tuple c) int d) list

27. What is the correct python code to display the last four characters of
string=“Digital India”
a) string[-4:] b) string [4:] c) string [*str] d) string [/4:]

28. How many times will the following code be executed.


a=5
while a>0:
print(a)
print(“Bye”)
a) 5 times b) Once c) Infinite d) None of these

29. The operator used to check if both the operands reference the same object
memory, is the .......... operator.
a) in b) is c) id d) ==

30. What does the following code do?


import random
print(random.randint(3, 9))

a) return a integer between 3 and 9(both excluded)


b) return a integer between 3 and 9(both included)
c) return a integer from the rangne 3 to 8
d) return a integer from the range 4 to 9
31. What will be the output of the following Python function if the random module
has already been imported?

random.randint(3.5,7)
a) Error
b) Any integer between 3.5 and 7, including 7
c) Any integer between 3.5 and 7, excluding 7
d) The integer closest to the mean of 3.5 and 7
4
NOTE: Refer the topic random module and the following functions
associated with it.
1) random.random()
2) random.randint()
3) random.randrange()

random()
Returns a random floating point number between 0 and 1:

random.random()
# Output: 0.66486093215306317

randint()

Returns a random integer between x and y (inclusive):

random.randint(x, y)

For example getting a random number between 1 and 8:

random.randint(1, 8)
# Output: 8

randrange()

random.randrange has the same syntax as range and unlike


random.randint, the last value is not inclusive:

random.randrange(100) # Random integer between 0 and 99


random.randrange(20, 50) # Random integer between 20 and 49
random.rangrange(10, 20, 3) # Random integer between 10 and 19
with step 3 (10, 13, 16 and 19)

You might also like