Python Programming (2180711) MCQs

MCQs of Introduction to Python

Showing 21 to 30 out of 170 Questions
21.
In python we do not specify types, it is directly interpreted by the compiler, so consider the following operation to be performed. >>>x = 13 ? 2 The objective is to make sure x has an integer value, select all that apply (python 3.xx)
(a) x = 13 // 2
(b) x = int(13 / 2)
(c) x = 13 % 2
(d) All of the mentioned
Answer:

Option (d)

22.
What error occurs when you execute the following Python code snippet? apple = mango
(a) Syntax Error
(b) Name Error
(c) Value Error
(d) Type Error
Answer:

Option (b)

23.
What will be the output of the following Python code snippet? def example(a):
a = a + '2'
a = a*2
return a >>>example(""hello"")
(a) Indentation Error
(b) Cannot perform mathematical operation on strings
(c) hello2
(d) hello2hello2
Answer:

Option (a)

24.
Which of the following results in a SyntaxError?
(a) Once upon a time…”, she said.
(b) He said, ‘Yes!'
(c) ‘3\’
(d) ’That’s okay”
Answer:

Option (c)

25.
What is the average value of the following Python code snippet? >>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
(a) 85
(b) 85.1
(c) 95
(d) 95.1
Answer:

Option (a)

26.
Select all options that print. hello-how-are-you
(a) print(‘hello’, ‘how’, ‘are’, ‘you’)
(b) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)
(c) print(‘hello-‘ + ‘how-are-you’)
(d) print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’)
Answer:

Option (c)

27.
What is the return value of trunc()?
(a) int
(b) bool
(c) float
(d) None
Answer:

Option (a)

28.
What is the output of print 0.1 + 0.2 == 0.3?
(a) TRUE
(b) FALSE
(c) Machine dependent
(d) Error
Answer:

Option (b)

29.
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
Answer:

Option (c)

30.
What is the type of inf?
(a) Boolean
(b) Integer
(c) Float
(d) Complex
Answer:

Option (c)

Showing 21 to 30 out of 170 Questions