Test Series - python

Test Number 4/108

Q: What is the average value of the following Python code snippet?

>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
A. 85.0
B. 85.1
C. 95.0
D. 95.1
Solution: Cause a decimal value of 0 to appear as output.
Q: 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’)
Solution: Execute in the shell.
Q: What is the return value of trunc()?
A. int
B. bool
C. float
D. None
Solution: Execute help(math.trunc) to get details.
Q: What is the output of print 0.1 + 0.2 == 0.3?
A. True
B. False
C. Machine dependent
D. Error
Solution: Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The round off errors from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17 between (0.1 + 0.2) and 0.3.
Q: 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
Solution: l (or L) stands for long.
Q: What is the type of inf?
A. Boolean
B. Integer
C. Float
D. Complex
Solution: Infinity is a special case of floating point numbers. It can be obtained by float(‘inf’).
Q: What does ~4 evaluate to?
A. -5
B. -4
C. -3
D. +3
Solution: ~x is equivalent to -(x+1).
Q: What does ~~~~~~5 evaluate to?
A. +5
B. -11
C. +11
D. -5
Solution: ~x is equivalent to -(x+1).
~~x = – (-(x+1) + 1) = (x+1) – 1 = x
~~x is equivalent to x
Extrapolating further ~~~~~~x would be same as x in the final result.
In the question, x value is given as 5 and “~” is repeated 6 times. So, the correct answer for “~~~~~~5” is 5.

You Have Score    /8