Mohammed Arif Mazumder
Quiz by , created more than 1 year ago

Quiz on Pre-Test (Python Basic), created by Mohammed Arif Mazumder on 07/02/2021.

1814
0
0
Mohammed Arif Mazumder
Created by Mohammed Arif Mazumder almost 4 years ago
Rate this resource by clicking on the stars below:
1 2 3 4 5 (0)
Ratings (0)
0
0
0
0
0

0 comments

There are no comments, be the first and leave one below:

Close

Pre-Test (Python Basic)

Question 1 of 10 Question 1 of 10

1

What is the output of the following code snippet: (You can see the picture too)
if 'bar' in {'foo': 1, 'bar': 2, 'baz': 3}:
print(1)
print(2)
if 'a' in 'qux':
print(3)
print(4)

Select one of the following:

  • 4

  • It doesn’t generate any output.

  • 1
    2
    3
    4

  • 1
    2
    4

Explanation

Question 2 of 10 Question 2 of 10

1

The following if/elif/else statement will raise a KeyError exception:
d = {'a': 0, 'b': 1, 'c': 0}

if d['a'] > 0:
print('ok')
elif d['b'] > 0:
print('ok')
elif d['c'] > 0:
print('ok')
elif d['d'] > 0:
print('ok')
else:
print('not ok')

Select one of the following:

  • True

  • False

Explanation

Question 3 of 10 Question 3 of 10

1

Shown below is a diagram of a simple dictionary:

Which of the following is not a valid way to define this dictionary in Python:

Select one of the following:

  • d = {
    ('foo', 100),
    ('bar', 200),
    ('baz', 300)
    }

  • d = dict(foo=100, bar=200, baz=300)

  • d = dict([
    ('foo', 100),
    ('bar', 200),
    ('baz', 300)
    ])

  • d = {'foo': 100, 'bar': 200, 'baz': 300}

  • d = {}
    d['foo'] = 100
    d['bar'] = 200
    d['baz'] = 300

Explanation

Question 4 of 10 Question 4 of 10

1

List a is defined as follows:
a = [1, 2, 3, 4, 5]
Select all of the following statements that remove the middle element 3 from a so that it equals [1, 2, 4, 5]:

Select one of the following:

  • a[2:2] = []

  • a[2] = []

  • del a[2]

  • a[0:3] = []

  • a.add(3)

Explanation

Question 5 of 10 Question 5 of 10

1

Which of the following would separate a string input_string on the first 2 occurences of the letter “e”?

Select one of the following:

  • input_string.split('e', 2)

  • 'e'.split(input_string, maxsplit=2)

  • 'e'.split(input_string, 2)

Explanation

Question 6 of 10 Question 6 of 10

1

What is the output of the following code snippet:
d = {'foo': 1, 'bar': 2, 'baz': 3}
while d:
print(d.popitem())
print('Done.')

Select one of the following:

  • ('baz', 3)
    ('bar', 2)
    ('foo', 1)
    Done.

  • The snippet doesn’t generate any output.

  • foo
    bar
    baz

  • Done.

Explanation

Question 7 of 10 Question 7 of 10

1

The function sqrt() from the math module computes the square root of a number.

Will the highlighted line of code raise an exception?
x = -100
from math import sqrt
x > 0 and sqrt(x)

Select one of the following:

  • False

  • True

Explanation

Question 8 of 10 Question 8 of 10

1

Which of the following mathematical operators can be used to concatenate strings:

Select one of the following:

  • *

  • -

  • +

  • /

Explanation

Question 9 of 10 Question 9 of 10

1

Suppose you have the following tuple definition:
t = ('foo', 'bar', 'baz')
Which of the following statements replaces the second element ('bar') with the string 'qux':

Select one of the following:

  • t(1) = 'qux'

  • It’s a trick question—tuples can’t be modified.

  • t[1:1] = 'qux'

  • t[1] = 'qux'

Explanation

Question 10 of 10 Question 10 of 10

1

What is value of this expression:
'a' + 'x' if '123'.isdigit() else 'y' + 'b'

Select one of the following:

  • 'axb'

  • 'ab'

  • 'axyb'

  • 'ax'

Explanation