Quiz: Python Part-1

To View Tricks: Login Required

Number of Questions: 37

Question: 21 -

Study the following function:

all([2,4,0,6])  

What will be the output of this function?

Options:
  1. False

  2. Invalid code

  3. True

  4. 0

  5. Answer:

    False

    Solution:

    If any element is zero, it returns a false value, and if all elements are non-zero, it returns a true value. Hence, the output of this "all([2,4,0,6])" function will be false.


Question: 22 -

Study the following code:

x = ['XX', 'YY']  

for i in a:  

    i.lower()  

print(a)  

What will be the output of this program?

Options:
  1. [XX, yy]

  2. ['xx', 'yy']

  3. ['XX', 'YY']

  4. None of these

  5. Answer:

    ['XX', 'YY']

    Solution not available.

Question: 23 -

Which one of the following syntaxes is the correct syntax to read from a simple text file stored in ''d:\java.txt''?

Options:
  1. Infile = open.file(''d:\\java.txt'',''r'')

  2. Infile = open(''d:\\java.txt'', ''r'')

  3. Infile = open(''d:\java.txt'',''r'')

  4. Infile = open(file=''d:\\\java.txt'', ''r'')

  5. Answer:

    Infile = open(''d:\\java.txt'', ''r'')

    Solution not available.

Question: 24 -

Study the following function:

import math  

abs(math.sqrt(36))  

What will be the output of this code?

Options:
  1. 6.0

  2. -6

  3. Error

  4. 6

  5. Answer:

    6.0

    Solution not available.

Question: 25 -

 Study the following program:

 
 
 
x = 1  

while True:  

    if x % 5 = = 0:  

        break  

    print(x)   

    x + = 1  

What will be the output of this code?

Options:
  1. 0 3 1

  2. None of these

  3. 2 1

  4. error

  5. Answer:

    error

    Solution:

    Syntax error, there should not be a space between + and =.