Computer science MCQ questions Class 12 Python

 1. Which of the following is valid arithmetic operator in Python?

(A) // (B) ?

(C) < (D) and

2. 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))

3. Which of the following is invalid?

(A) _a = 1 (B) __a = 1

(C) __str__ = 1 (D) none of the mentioned

4. Which of the following is/are sorting technique?

(A) Bubble sort (B) Insertion sort

(C) Both A and B (D) None of these

5. To open a file “c:\scores.txt” for reading, we use ......................... .

(A) infile = open(“c:\scores.txt”, “r”) (B) infile = open(“c:\\scores.txt”, “r”)

(C) infile = open(file = “c:\scores.txt”, “r”) (D) infile = open(file = “c:\\scores.txt”, “r”)

6. All keywords in Python are in ......................... .

(A) lower case (B) UPPER CASE

(C) Capitalized (D) None of these

7. To read two bytes from a file object infile, we use ............................. .

(A) infile.read(2) (B) infile.read()

(C) infile.readline() (D) infile.readlines()

8. Which function helps us to randomize the items of a list?

(A) shuffle() (B) mean()

(C) choice() (D) max()

9. Which of the following is valid for loop in Python?

(A) for(i=0; i<n; i++) (B) for i in range(0,5):

(C) for i in range(0,5) (D) for i in range(5)

10. It determines the mode in which the file has to be opened.

(A) file name (B) access_mode

(C) dump (D) pickle

11. 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’]

12. Which type of error occurs when rules of programming language are misused?

(A) Syntax error (B) Semantic error

(C) Run time error (D) Logical error

13. Which of the following is the use of id() function in python?

(A) id() returns the identity of the object (B) Every object doesn’t have a unique Id

(C) Both (A) and (B) (D) None of the mentioned

14. Which of the following is/are compile time errors?

(A) Syntax error (B) Semantic error

(C) A and B both (D) None of these

15. Which of the following is an invalid statement?

(A) abc = 1,000,000 (B) a b c = 1000 2000 3000

(C) a,b,c = 1000, 2000, 3000 (D) a_b_c = 1,000,000

16. What keyword would you use to add an alternative condition to an if statement?

(A) else if (B) elseif

(C) elif (D) None of these

17. Which of the following refers to mathematical function?

(A) sqrt (B) Rhombus

(C) add (D) Rqrt Add

18. Which sorting technique compares two adjoining values and exchanges them?

(A) Bubble sort (B) Insertion sort

(C) Both A and B (D) None of these

19. Which of the following is not a complex number?

(A) k = 2 + 3j (B) k = complex(2, 3)

(C) k = 2 + 3l (D) k = 2 + 3J

20. In a Python program, a control structure ........................ .

(A) Defines program-specific data structures

(B) Directs the order of execution of the statements in the program

(C) Dictates what happens before the program starts and after it terminates

(D) None of the above

21. Which of the following is an invalid variable?

(A) my_string_1 (B) 1st_string

(C) foo (D) _my_string

22. What are the two main types of functions?

(i) Custom function

(ii) Built in function

(iii) User defined function

(iv) System function

(A) (i) and (ii) (B) (ii) and (iii)

(C) (iii) and (iv) (D) (i) and (iv)

23. Text files store information in ......................... characters.

(A) ASCII (B) Unicode

(C) (A) and (B) (D) None of these

24. Which type of elements are accepted by random. shuffle()?

(A) tuples (B) dictionaries

(C) lists (D) strings

25. Which statement will check if a is equal to b?

(A) if a = b: (B) if a == b:

(C) if a === c: (D) if a == b

SECTION-B

26. What will be the output of the following code?

 print (type(type(int)))

(A) type ‘int’ (B) <class ‘type’>

(C) Error (D) <class ‘int’>

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

 f = None

 for i in range (5):

 with open(“data.txt”, “w”) as f:

 if i > 2:

 break

 print(f.closed)

(A) True (B) False

(C) None (D) Error

28. What will be the output of the following code?

 x = “abcdef”

 i = “i”

 while i in x:

 print(i, end=” “)

(A) a b c d e f (B) abcdef

(C) i i i i i ... (D) No output

29. What will be the output of the following python code?

 def cube (x):

 return x * x * x

 x = cube (2)

 print (x)

(A) 2 (B) 4

(C) 8 (D) 20

30. What will be output of this expression:

 ‘p’ + ‘q’

(A) pq (B) rs

(C) pqrs (D) pq12

31. What will be the output of the following code?

 L = [‘a’,’b’,’c’,’d’]

 print (“ “.join(L))

(A) Error (B) a b c d

(C) [‘a’,’b’,’c’,’d’] (D) None

32. What is the output when the following code is executed ?

 print(r”\nhello”)

(A) a new line and hello (B) \nhello

(C) the letter r and then hello (D) Error

33. What will be the output of the following code?

 x = 12

 for i in x:

 print(i)

(A) 1 2 (B) 1, 2

(C) Error (D) None of the above

34. What is the output of 0.1 + 0.2 == 0.3?

(A) True (B) False

(C) Machine dependent (D) Error

35. What is the output of “hello”+1+2+3 ?

(A) hello123 (B) hello

(C) Error (D) hello6

36. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3] what is list1 after list1.pop(1)?

(A) [3, 4, 5, 20, 5, 25, 1, 3] (B) [1, 3, 3, 4, 5, 5, 20, 25]

(C) [3, 5, 20, 5, 25, 1, 3] (D) [1, 3, 4, 5, 20, 5, 25]

37. In python ~x=-(x+1) then, what does ~~~~~5 evaluate to?

(A) -6 (B) -11

(C) +11 (D) -5

38. Consider the following code and find the answer :

 x = 10

 print x

 x = “Anuj’’

 print x

(A) 10 (B) 10

Most recent Anuj

(C) call back error (D) None of these

invalid command

39. Identify the most probable incorrect output of random ( ).

(A) 0.02235319431 (B) 1.0234567

(C) 0.0003287169 (D) 0.001234567

40. A text file “MyData.txt” contains following data:

 Hello \n

 \n

 \n

 Welcome to AGRA

 \n

 How \n

 Are

 You

What would be the output of the following code:

 fn = open (“MyData.txt“, “r“)

 lst=fn.readlines()

 print lst[0],

 print lst[3],

 print lst[1],

 print lst[5]

(A) Hello (B) Hello Welcome to AGRA

Welcome to AGRA How

How

(C) Hello Welcome to AGRA How (D) Hello

Welcome to AGRA How

41. What will be the output of the following code?

 print(math.ceil (random.random( )))

(A) 2.0 (B) will be different every time

(C) 1.0 (D) None of these.

42. Identify the most probable contents that the file “friends.txt” will have after execution of the

following code:

 fn=open (“friends.txt”,”w”)

 for i in range(5):

 name = input (“Enter your friends name“)

 fn.write(name)

 fn.close()

 Consider the input to be:

 Anuj

 Anubhav

 Siddhant

 Arnav

 Abhay

(A) AnujAnubhavSiddhantArnavAbhay (B) Anuj

Anubhav

Siddhant

Arnav

Abhay

(C) Anuj Anubhav Siddhant Arnav Abhay (D) None of these

43. a = input (‘‘ Enter any number ’’)

 b = input (‘‘ Enter any number )

 c = a + b

 print (c)

 Predict the output of the above code if input is 56 & 72

(A) 128 (B) 5672

(C) 120 (D) Error will be displayed.

44. Identify the possible set of outputs for the following code.

 print (math.pow (random.randint ( 1, 4 ), 3))

 If the same statement is repeated 4 times

(1) 18278 (2) 1234

(3) 2231 (4) 182764

(5) 2764864 (6) 12723

(A) 1, 2 and 3 (B) 1, 4 and 5

(C) 3, 5 and 6 (D) 2, 4, 6

45. Which of the following sets is the most probable output if the below given print statement is

repeated three times?

 print (12 + random . random (5)

(A) 12.0123, 13.4567, 18.3264 (B) 12.0123, 13.4567, 16.3149

(C) 14.8961, 15.6794, 11.8910 (D) 14.8961, 15.6792, 17.1234

46. Consider the following logical expression (7 > 5) or (50 < 100/0). What will this expression evaluate

to?

(A) Gives an error (B) False

(C) Invalid statement (D) True

47. Identify the output of the following code:

 fn = open (r’E:\myFile.txt’, “r”)

 str = ““

 while str:

 str = fn.readline( )

 print str,

 fn.close( )

(A) All the lines of the file “myfile.txt” will be printed

(B) The contents of the file will be printed at one go

(C) The complete file will be read in a list str

(D) Contents of the file will be read one line at a time in string strand then printed.

48. Consider the code given below:

 def check (a):

 a = math.sqrt(a)

 return(a)

 print(a)

 check(25)

 The output will be:

(A) Error statement (B) 25

(C) 5 (D) Nothing will be printed

49. Name the file that is always opened in write mode.

(A) sys.stdin (B) write.txt

(C) Binary file (D) sys.stdout

                       SECTION-C

            CASE STUDY BASED QUESTIONS

This section consists of 6 Questions (50 -55) Attempt any 5 questions.

 Consider the following code and answer the questions that follow:

 Book = { 1 : ‘Thriller’, 2 : ‘Mystery’, 3 : ‘Crime’, 4 : ‘Children Stories’)

 Library = { ‘5’ : ‘Madras Diaries’, ‘6’ : ‘Malgudi Days’}

50. Ramesh needs to change the title in the dictionary Book from ‘Crime’ to ‘Crime Thriller’. He has

written the following command:

 Book[‘Crime’]=’Crime Thriller’

 But he is not getting the answer . Help him choose the correct command:

(A) Book[2]=’Crime Thriller’ (B) Book[3]=’Crime Thriller’

(C) Book[2]=(’Crime Thriller’) (D) Book[3]=(’Crime Thriller’)

51. The command to merge the dictionary Book with Library the command would be:

(A) d=Book+Library

(B) print(Book+Library)

(C) Book.update(Library)

(D) Library.update(Book)

52. What will be the output of the following code:

 print(list(Library))

(A) [‘5’,’Madras diaries’,’6’,’Malgudi Days’]

(B) (‘5’,’Madras diaries’,’6’,’Malgudi Days’)

(C) [’Madras diaries’,’Malgudi Days’]

(D) [‘5’,’6’]

53. In order to check whether the key 2 is present in the dictionary Book, Ramesh uses the following

command:

 2 in Book

 He gets the answer ‘True’. Now to check whether the name ‘Madras Diaries’ exists in the dictionary

Library, he uses the following command: ‘Madras Diaries’ in Library but he gets the answer as

‘False’. Select the correct reason for this:

(A) We cannot use the in operator with values. It can be used with keys only.

(B) We must use the function Library, values() along with the in operator.

(C) We can use the Library.items() function instead of the in operator.

(D) Both B and C above are correct.

54. With reference to the above declared dictionaries, predict the output of the following code fragments










55. Every time Ramesh prints the dictionary, he gets different output because:

(A) dictionaries are unordered

(B) dictionaries are ordered

(C) dictionaries keep on changing values associated with keys.

(D) none of these

Comments

Post a Comment

Popular posts from this blog

Diagonal Relationship between Beryllium and Aluminium || Relation between Beryllium and Aluminium

KVS CBSE Worksheets CHAPTER 1 Electric Charges and Fields Class 12

Kinematics Important Questions Of Physics

QUANTUM NUMBERS (Principal, Azimuthal, Magnetic and Spin)

NCERT Chemical Reactions and Equations Solutions || NCERT Solution Class 10 Science Chapter 1 || Chemistry || Science ||