Computer science MCQ questions Class 12 Python

 1. All keywords in Python are in ....................... except three keywords.

(A) lower case (B) UPPER CASE

(C) Capitalized (D) None of the mentioned

2. To read the entire remaining contents of the file as a string from a file object infile, we use

....................... .

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

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

3. How many types of error are there in Python?

(A) One (B) Two

(C) Three (D) Four

4. A byte-stream is converted back into an object hierarchy by the process called:

(A) Pickling (B) dumping

(C) loading (D) Unpickling.

5. Negative byte value in seek() will :

(A) Give an error

(B) Move the pointer to end of file

(C) Move the file pointer in reverse direction

(D) Move the file pointer to EOF

6. Which of the following is true for variable names in Python?

(A) unlimited length

(B) all private members must have leading and trailing underscores

(C) underscore and ampersand are the only two special characters allowed

(D) none of the mentioned

7. Which of these in not a core data type?

(A) Lists (B) Dictionary

(C) Tuples (D) Class

8. Constant(s) available in Math module is/are:

(A) math.pi (B) math.e

(C) math.pie (D) Both (A) & (B)

9. The variable that stores the name of top level statement is:

(A) _name_ (B) _main_

(C) _init.py (D) _init_

10. Which of the following sequences would be generated in the given line of code?

 range (5, 0, -2)

(A) 5 4 3 2 1 0 -1 (B) 5 4 3 2 1 0

(C) 5 3 1 (D) None of the above

11. Which of the following statements are true?

(A) When you open a file for reading, if the file does not exist, an error occurs

(B) When you open a file for writing, if the file does not exist, a new file is created

(C) When you open a file for writing, if the file exists, the existing file is overwritten with the new

file

(D) All of the mentioned

12. Sorting means arranging the elements in

(A) ascending order (B) descending order

(C) Either A or B (D) None of these

13. Which function is used to split a line in columns?

(A) split() (B) spt()

(C) split_line() (D) All of these

14. A sequence of characters surrounded by quotes:

(A) Comment (B) Document string

(C) String literal (D) Multiline comment

15. ................. is a file containing variables, class, definitions, statements and functions related to a

particular task.

(A) docstrings (B) functions

(C) Python Module (D) _main_

16. Each line of text in a text file is terminated by ......................

(A) ‘\n’ (B) Carriage return

(C) Both (A) & (B) (D) Neither (A) and (B)

17. To read 5 bytes from a file, the statement is

(A) read (5) (B) <filehandle>. read (5)

(C) read (5). <filehandle> (D) <filehandle>.(5)

18. .................... is used to indicate something that has yet not been created.

(A) True (B) False

(C) None (D) Literal Collection.

19. Identify the incorrect form of import statement.

(A) from <module> import <object1> [<object2>, […]]

(B) from <module> import <object>

(C) from <module> import all

(D) All of the above

20. Below are given steps to process a file in python. Arrange them in correct order

1. Open a file and assign its reference to a file object.

2. determine the type of file usage.

3. close the file.

4. Process the file

(A) 1 — 2 — 3 — 4 B. 4 — 2 — 3 — 1

(C) 2 — 1 — 3 — 4 (D) 2 — 1 — 4 — 3

21. The ‘w’ mode will:

(A) Create a new file for writing if it doesn’t exist.

(B) Overwrite the file that already exist.

(C) Can be used only for writing.

(D) All of the above.

22. Name the standard input/output files opened by Python when a user starts Python.

(A) stdin (B) stdout

(C) sys.stdin & sys.stdout (D) stdin & stdout

23. A file object is also known as

(A) File identifier (B) File mode

(C) File variable (D) File handle

24. All the functions on a date file are performed through:

(A) open( ) (B) file object

(C) file( ) (D) write( )

25. ..................... forces the writing of data on disc still pending in output buffer.

(A) write ( ) (B) writelines ( )

(C) flush ( ) (D) close ( )

SECTION-B

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

 i=0

 def change(i):

 i=i+1

 return i

 change(1)

 print(i)

(A) 1 (B) Nothing is displayed

(C) 0 (D) Error

27. What will be the output of the following code, if the file stud.txt contains following data?

 10~34.50~67.85~89.0\n

 11~47.78~89.95~67.45\n

 13~12.53~100.00~56.20\n

 fh=open("stud.txt","w")

 line=fh.readline().rstrip('\n')

 record = line.split('~')

 print(record)

(A) ['10','34.50,'67.85','89.0'] (B) [10,11,13]

(C) [10,34.50,67.85,89.0] (D) Error will be generated

28. The statement

 name = u ‘‘Neelam’’ :

(A) Gives an error (B) declares of a unicode string

(C) Stores an ASCII string (D) None of these

29. ....................... refer to use an expression as part of a larger expression.

(A) Functions (B) Compositions

(C) Modules (D) None of these

30. int (‘010’, 8) will give

(A) 00000010 (B) 18

(C) 9 (D) Not possible.

31. A file ABC.txt contains the following data

 12~47.85~64.25~89\n.

 What can you say about the type of the file?

(A) File contains the students data (B) File contains numbers.

(C) It is a text file. (D) It is a delimited text file.

32. A multiline string can be created by:

(A) Adding a backslash at the end of the physical line

(B) By enclosing the multiple lines of string in triple quotes.

(C) By enclosing the string in parenthesis (‘( )’ )

(D) Both (A) & (B)

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

 print ‘doesn/’t’

 print “doesn’/’t”

 print “yes,” he said.’

 print “/”yes, /” he said.”

(A) doesn’t (B) doesn’t

doesn/t doesn’t

“yes”, he said. Most recent traceback error

“yes,” he said “yes,” he said.

(C) most recent true back error (D) doesn’t

doesn’t doesn’t

“yes,” he said. “yes,” he said.

“yes,” he said “yes, / he said.

34. Predict the output of each of the three code fragments.

1. a = 20

a + 1

print (a)

2. a = 20

a + = 1

print(a)

3. a = 20

a = a + 1

print(a)

(A) 1.21 2.21 3.20 (B) 1.20 2.21 3.21

(C) 1.20 2.20 3.21 (D) 1.20 2.21 3.20.

35. What will be the output of print (len (str (5 > 50)))?

(A) Most recent traceback error (B) 4

(C) 5 (D) None of these

36. Predict the output

 num = 20.5

 z = 3

 result = z**3 + num//z

 print (result)

(A) 3381.4 (B) 0

(C) Error (D) 33.0

37. Predict the output of the following expression.

 print(4*len('welcome')/((len("python")%3)+2.0))

(A) 14 (B) 27

(C) 12 (D) 31

38. Predict the output of 3 < (10 or 2)

(A) True (B) False

(C) Syntax Error (D) None of these

39. What will the following expression evaluate to print (complex (1.5) + int (2.5) + 200)

(A) Syntax Error (B) (203.5 + 0j)

(C) (202 + 1j) (D) None of these

40. What would be the output of print (math. fabs (–5.0/2))

(A) – 2.5 (B) 2.5

(C) – 2 (D) – 2.5

41. What will be the output of:

 print (int (10.78/3) < len (“10.78”))

(A) True (B) False

(C) Syntax Error (D) None of these.

42. Find the output of the below given code when x = 0, y = 1, z = 1

 x = int (input (“Enter a number”))

 y = int (input (“Enter second number”))

 z = int (input (“Enter third number”))

 if x < y < z :

 print (“stream 1”)

 elif x > y > z :

 print (“stream 2”)

 else : print (“stream 3”)

 print (“is selected for you”)

(A) stream 3 (B) stream 3 is selected for you

is selected for you

(C) stream 1 (D) stream 2 is selected for you

is selected for you

43. Identify the statement which will give output 2.

(A) print(5/2) (B) print(5.0//2)

(C) print((int)5.0//2) (D) print(math.fabs(-5.0/2))

44. Find the output

 b=eval('65+23')

 print(b)

(A) 6523 (B) Syntax error

(C) 98 (D) None of these

45. Predict the output of the given code for x = 30

 if (x > 50) :

 if (x < 60) :

 print (“Got it”)

 else :

 print (“Well tried”)

 else :

 if (x > 30) :

 print (“Just missed”)

 else :

 pritn (“Eureka”)

(A) Got it (B) Well tried

(C) Just missed (D) Eureka

46. What will be the output of following code?

 deffunc(a,b=5,c=10):

 poly=2*a*2-5*b+c

 a=b + c

 print(poly)

 func(6,c=4)

(A) 5 (B) 4

(C) 10 (D) 3

47. What will the following expression evaluate to :

 (2/int (1.5) + 200)

(A) 202 (B) 201

(C) Syntax Error (D) None of these

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

 def power(x, y=2):

 r = 1

 for i in range(y):

 r = r * x

 return r

 print(power(3))

 print(power(3, 3))

(A) 9 (B) 9

27 9

(C) 27 (D) Error

27

49. Predict the output

 for a in 10, 12, 14, 16, 18 :

 print(a)

(A) 10, 12, 14, 16, 18 (B) 10, 14, 16

(C) Syntax Error (D) 10

12

14

16

18

SECTION-C

CASE STUDY BASED QUESTIONS

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

I. Attempt any 5 questions out of 6.

Module

 A Python module can be defined as a python program file which contains a python code including

python functions, classes, or variables. In other words, we can say that our python code file saved

with extension (.py) is treated as the module. We may have a runnable code inside the python

module.

 Modules in Python provide us the flexibility to organize the code in a logical way. To use the

functionality of one module into another, we must have to import the specific module.

 The import statement is used to import all the functionality of one module into another. Here, we

must notice that we can use the functionality of any python source file by importing that file as

the module into another python source file. We can import multiple modules with a single import

statement, but a module is loaded once regardless of the number of times, it has been imported

into our file.

50. Which extension is used to save the Python file?

(A) .py (B) .pyth

(C) .thon (D) .python

51. What is the use of import statement?

(A) to import all functionality of one module

(B) to import all functionality of one module into another

(C) to import all functionality

(D) None of these.

52. .................... is a file containing Python definitions and statements.

(A) Module (B) List

(C) Tuple (D) Dictionary

53. How many kinds of module are there in Python?

(A) Built in (B) User defined

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

54. Which keyword is used to import the module?

(A) import module (B) module

(C) import (D) None of these

55. Name the Python module used for renaming and deleting files:

(A) pickle module (B) file module

(C) IO module (D) os module

Comments

Post a Comment

Popular posts from this blog

QUANTUM NUMBERS (Principal, Azimuthal, Magnetic and Spin)

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

Math question

Solar System, Planets, Moons, Asteroid Belt,Kuiper Belt and Oort Cloud, Comets and Meteoroids