Insert the correct snippet so that the program produces the expected output.
Expected output:
Code:
- A . b = 0 not in list
- B . b = list[0]
- C . b = 0 in list
- D . b = False
Assuming that the tuple is a correctly created tuple, the fact that tuples are immutable means that the following instruction:
- A . is illegal
- B . may be illegal if the tuple contains strings
- C . can be executed if and only if the tuple contains at least two elements
- D . is fully correct
What is the expected output of the following code?
- A . 2
- B . 4
- C . 5
- D . 3
What is the expected output of the following code?
- A . [1, 3]
- B . [1, 4]
- C . [4, 3]
- D . [1, 3, 4]
What is the expected output of the following code?
- A . [‘Peter’, 404, 3.03, ‘Wellert’, 33.3]
- B . None of the above.
- C . [404, 3.03]
- D . [‘Peter’, ‘Wellert’]
Take a look at the snippet, and choose the true statements: (Choose two.)
- A . nums is longer than vals
- B . nums and vals are of the same length
- C . vals is longer than nums
- D . nums and vals refer to the same list
What is the output of the following snippet?
- A . 12
- B . (2, 1)
- C . (1, 2)
- D . 21
What is the expected output of the following code?
print(list(‘hello’))
- A . hello
- B . [h, e, l, l, o]
- C . [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
- D . [‘h’ ‘e’ ‘l’ ‘l’ ‘o’]
- E . None of the above.
What will be the output of the following code snippet?
- A . [1, 3, 5, 7, 9]
- B . [8, 9]
- C . [1, 2, 3]
- D . [1, 2]
What will be the output of the following code snippet?
- A . 3
- B . 2
- C . 4
- D . 1
What is the output of the following snippet?
- A . two
- B . one
- C . (‘one’, ‘two’, ‘three’)
- D . three
What is the expected output of the following code?
- A . [3, 1, 25, 5, 20, 5, 4]
- B . [1, 3, 4, 5, 20, 5, 25]
- C . [3, 5, 20, 5, 25, 1, 3]
- D . [1, 3, 3, 4, 5, 5, 20, 25]
- E . [3, 4, 5, 20, 5, 25, 1, 3]
Which of the following sentences is true?
- A . str1 and str2 are different (but equal) strings.
- B . str1 and str2 are different names of the same strings.
- C . str1 is longer than str2
- D . str2 is longer than str1
The fact that tuples belong to sequence types means:
- A . they can be modi fi ed using the del instruction
- B . they can be extended using the .append() method
- C . they are actually lists
- D . they can be indexed and sliced like lists
What is the output of the following code?
- A . [1, 1, 1]
- B . [3, -1, 1]
- C . [3, 1, 1]
What is the expected output of the following code?
- A . The code is erroneous.
- B . 6
- C . 5
- D . 4
What is the expected output of the following code?
- A . (‘Peter’: 30, ‘Paul’: 31)
- B . (‘Peter’, ‘Paul’)
- C . [‘Peter’: 30, ‘Paul’: 31]
- D . [‘Peter’, ‘Paul’]
What is the output of the following snippet?
- A . 2
- B . 4
- C . The snippet is erroneous (invalid syntax)
What is the expected output of the following code?
- A . (4)
- B . 4
- C . (4,)
- D . 44
What is the output of the following snippet?
- A . [1, 1, 2, 2]
- B . [1, 1, 1, 2]
- C . [1, 2, 1, 2]
- D . [1, 2, 2, 2]
What is the expected output of the following code?
- A . 4
- B . 6
- C . 5
- D . 3
A data structure described as LIFO is actually a:
- A . stack
- B . tree
- C . list
- D . heap
How would you remove all the items from the d dictionary?
Expected output:
Code:
- A . d.del()
- B . d.remove()
- C . del d
- D . d.clear()
What is the expected output of the following code?
- A . three
- B . (‘one’, ‘two’, ‘three’)
- C . two
- D . one
What is the expected output of the following code?
- A . False
- B . 1
- C . 0
- D . True
Which one of the lines should you put in the snippet below to match the expected output?
Expected output:
Code:
- A . reverse(list)
- B . list.reversed()
- C . list.reverse()
- D . reversed(list)
What is the expected output of the following code?
- A . [‘1’, ‘2’, ‘3’, ‘4’]
- B . (1, 2, 3, 4)
- C . (‘1’, ‘2’, ‘3’, ‘4’)
- D . The code is erroneous.
What is the expected output of the following code?
- A . (2)
- B . (2,)
- C . 2
- D . The code is erroneous.
What is the output of the following snippet?
- A . -2
- B . 3
- C . -1
- D . 1
An alternative name for a data structure called a stack is:
- A . LIFO
- B . FIFO
- C . FOLO
What is the expected output of the following code?
- A . [7, 3, 23, 42]
- B . [7, 20, 23, 42]
- C . [10, 20, 42]
- D . [10, 20, 23, 42]
Take a look at the snippet and choose one of the following statements which is true:
- A . vals is longer than nums
- B . nums and vals are of the same length
- C . nums is longer than vals
What is the expected output of the following code?
- A . (1, 2)
- B . The code is erroneous.
- C . {‘a’:1, ‘b’:2}
- D . [1,2]
How many elements does the L list contain?
- A . one
- B . two
- C . three
- D . zero
What is the expected output of the following code?
- A . (‘Peter’, ‘Peter’,)
- B . PeterPeter
- C . The code is erroneous.
- D . (‘Peter’)
- E . ()
What is the expected output of the following code?
- A . The program will cause an error.
- B . (1, 4, 9)
- C . (‘A’, ‘D’, ‘Z’)
- D . (5.0, 7.5, 9.9)
What is the expected output of the following code?
- A . The code is erroneous.
- B . 1
- C . 0
- D . None
What is the expected output of the following code?
- A . 22
- B . 12
- C . 0
- D . 11
What is the expected output of the following code?
- A . (2, 1, 1)
- B . (1, 1, 1)
- C . (2, 2, 2)
- D . The code is erroneous.
Which one of the lines should you put in the snippet below to match the expected output?
Expected output:
Code:
- A . sorted(list)
- B . sort(list)
- C . list.sort()
- D . list.sorted()
Which of the following sentences are true about the code? (Choose two.)
- A . nums and vals are different lists
- B . vals is longer than nums
- C . nums and vals are different names of the same list
- D . nums and vals have the same length
The second assignment:
- A . extends the list
- B . doesn’t change the list’s length
- C . shortens the list
What is the expected output of the following code?
- A . efg
- B . abc
- C . def
- D . The code is erroneous.
- E . abcde
- F . None of the above.
Which function does in-place reversal of objects in a list?
- A . list.sort([func])
- B . list.pop(obj=list[-1])
- C . list.remove(obj)
- D . list.reverse()
What is the output of the following snippet?
- A . [1, 2, 3]
- B . [3, 3, 3]
- C . [3, 2, 1]
- D . [1, 1, 1]
What snippet would you insert in the line indicated below to print .
The highest number is 10 and the lowest number is 1. to the monitor?
A ) None of the above.
B )
C )
D )
- A . Option A
- B . Option B
- C . Option C
- D . Option D
What is the output of the following snippet?
- A . [‘Mary’, ‘had’, ‘a’, ‘little’, ‘lamb’]
- B . [‘Mary’, ‘had’, ‘a’, ‘lamb’]
- C . [‘Mary’, ‘had’, ‘a’, ‘ramb’]
- D . No output, the snippet is erroneous
What is the expected output of the following code?
- A . Paul
- B . Mary
- C . The code is erroneous.
- D . None of the above.
- E . Peter
What is the expected output of the following code?
- A . 1
- B . 4
- C . 3
- D . 2
What is the expected output of the following code?
- A . 0
- B . 1
- C . The code is erroneous.
- D . 2
What is the expected output of the following code?
- A . The code is erroneous.
- B . [‘Peter’, ‘Jane’, ‘Mary’]
- C . [‘Peter’, ‘Jane’]
- D . [‘Paul’, ‘Mary’, ‘Jane’]
What is the expected output of the following code?
- A . 24
- B . 13
- C . 31
- D . 42
What is the expected output of the following code?
- A . 4
- B . 10
- C . Nothing gets printed.
- D . The code is erroneous.
After execution of the following snippet, the sum of all vals elements will be equal to:
- A . 4
- B . 5
- C . 2
- D . 3
What is the expected output of the following code?
- A . 4
- B . 2
- C . 10
- D . 0
- E . 1
- F . 3
What is the output of the following snippet?
- A . [0, 1, 9, 16]
- B . [0, 1, 4, 16]
- C . [0, 1, 4, 9]
- D . [1, 4, 9, 16]
What is the expected output of the following code?
- A . [4, 3, 2, 1]
- B . [4, 3, 2]
- C . [4, 3]
- D . The code is erroneous.
Take a look at the snippet and choose one of the following statements which is true:
- A . nums and vals are of the same length
- B . nums is longer than vals
- C . vals is longer than nums
What is the expected output of the following code?
- A . 01
- B . 10
- C . The code is erroneous.
- D . 00
What code would you insert instead of the comment to obtain the expected output?
Expected output:
Code:
- A . print(k[0])
- B . print(k)
- C . print(k[‘0’])
- D . print(k["0"])
What is the expected output of the following code?
- A . 15913
- B . 1234
- C . 13 14 15 16
- D . 481216
What is the expected output of the following code?
- A . The code is erroneous.
- B . 2
- C . 1
- D . 0
What is the expected output of the following code?
- A . [2]
- B . [3, 4, 5]
- C . The program will cause an error.
- D . [2, 3, 4, 5]
You develop a Python application for your company.
A list named employees contains 200 employee names, the last fi ve being company management. You need to slice the list to display all employees excluding management.
Which code segments can you use? (Choose two.)
- A . employees[1:-5]
- B . employees[0:-5]
- C . employees[:-5]
- D . employees[0:-4]
- E . employees[1:-4]
What is the expected output of the following code?
- A . 112345
- B . 234561
- C . 234566
- D . 123456
What is the expected output of the following code?
- A . [1, 10, 3, 20, 5, 30, 7, 40, 9, 50, 60]
- B . [1, 2, 10, 20, 30, 40, 50, 60]
- C . The code is erroneous.
- D . [10, 2, 20, 4, 30, 6, 40, 8, 50, 60]
What is the expected output of the following code?
- A . 2
- B . 1
- C . The code is erroneous.
- D . 3
- E . 4
What is the expected output of the following code?
- A . hellopeter
- B . hello@Peter!!
- C . hello@peter!!
- D . None
Consider the following list.
data = [1, 5, 10, 19, 55, 30, 55, 99]
Which of the code snippets below would produce a new list like the following?
[1, 5, 10, 99]
A )
B )
C ) None of the above.
D )
E )
- A . Option A
- B . Option B
- C . Option C
- D . Option D
- E . Option E
What is the expected output of the following code?
- A . 0
- B . 1
- C . False
- D . True
What is the output of the following snippet?
- A . [1, 2, 3, 1, 2, 3]
- B . [3, 2, 1, 1, 2, 3]
- C . [1, 1, 1, 1, 2, 3]
- D . [1, 2, 3, 3, 2, 1]
Insert the correct snippet to convert the t tuple to a dictionary named d.
Expected output:
Code:
- A . t >> d.dict
- B . d = dict(t)
- C . d.dict(t)
- D . d = t(dict)
How many elements does the my_list list contain?
- A . one
- B . three
- C . two
What is the expected output of the following code?
- A . 72342
- B . 74223
- C . 42237
What is the expected output of the following code?
- A . {(2, 3): 2}
- B . {(1, 2): 1}
- C . The code is erroneous.
- D . 1
Take a look at the snippet and choose the true statement:
- A . vals is longer than nums
- B . nums is longer than vals
- C . nums and vals have the same length
- D . The snippet will cause a runtime error.
What is the expected output of the following code?
- A . 3
- B . The code is erroneous.
- C . 6
- D . 7
What would you insert instead of ???, so that the program checks for even numbers?
- A . x % ‘even’ == True
- B . x % 2 == 1
- C . x % 2 == 0
- D . x % x == 0
- E . x % 1 == 2
What value will be assigned to the x variable?
- A . 0
- B . True
- C . False
- D . 1
What is the expected output of the following code?
x = 1 // 5 + 1 / 5
print(x)
- A . 0
- B . 0.2
- C . 0.0
- D . 0.4
An operator able to check whether two values are not equal is coded as:
- A . <>
- B . !=
- C . =/=
- D . not ==
The result of the following addition:
123 + 0.0
- A . cannot be evaluated
- B . is equal to 123
- C . is equal to 123.0
What will be the output of the following code snippet?
print (3 / 5)
- A . None of the above.
- B . 0
- C . 0.6
- D . 6/10
What will be the output of the following code snippet?
- A . 1
- B . 4
- C . 2
- D . 3
- E . None
What is the expected output of the following code?
x = 1 / 2 + 3 // 3 + 4 ** 2
print(x)
- A . 17
- B . 17.5
- C . 8.5
- D . 8
You develop a Python application for your company. You have the following code.
Which of the following expressions is equivalent to the expression in the function?
- A . (a + b) * (c – d)
- B . (a + (b * c)) – d)
- C . (a + ((b * c) – d)
- D . None of the above.
What is the output of the following code?
- A . The output cannot be predicted.
- B . 2
- C . The program will cause an error.
- D . 1
What is the expected output of the following code?
x = 28
y = 8
print(x / y)
print(x // y)
print(x % y)
- A . 1 | 3.0
2 | 3
3 | 2 - B . 1 | 3.5
2 | 3
3 | 4 - C . 1 | 3
2 | 3.5
3 | 4 - D . 1 | 3.5
2 | 3.5
3 | 2
Which of the following statements are true? (Choose two.)
- A . The result of the / operator is always an integer value.
- B . The ** operator uses right-sided binding.
- C . The right argument of the % operator cannot be zero.
- D . Addition precedes multiplication.
Which of the following statements is false?
- A . The right argument of the % operator can not be zero.
- B . The ** operator has right-to-left associativity.
- C . Multiplication precedes addition.
- D . The result of the / operator is always an integer value.
What is the expected output of the following code?
print (1 // 2 * 3)
- A . 4.5
- B . 0.16666666666666666
- C . 0.0
- D . 0
What is the expected output of the following code?
- A . True True
- B . True False
- C . False False
- D . False True
The ** operator:
- A . performs duplicated multiplication
- B . does not exist
- C . performs oating-point multiplication
- D . performs exponentiation
Only one of the following statements is true – which one?
- A . addition precedes multiplication
- B . multiplication precedes addition
- C . neither statement can be evaluated
The += operator, when applied to strings, performs:
- A . Subtraction
- B . Concatenation
- C . Multiplication
What is the expected output of the following code?
- A . 8
- B . 7.0
- C . 8.0
- D . 9.0
Consider the following code.
The value eventually assigned to x is equal to:
- A . 1
- B . 0
- C . True
- D . False
What is the output of the following code?
- A . The program will cause an error.
- B . False
- C . None
- D . True
What is the expected output of the following code?
x = 1 + 1 // 2 + 1 / 2 + 2
print(x)
- A . 3
- B . 4.0
- C . 4
- D . 3.5
What value will be assigned to the x variable?
- A . False
- B . 0
- C . 1
- D . True
What is the expected output of the following code?
print(1 / 1)
- A . 1
- B . 1.0
- C . This can not be predicted.
- D . This can not be evaluated.
What is the expected output of the following code?
- A . 1 | False
2 | False - B . 1 | True
2 | True - C . 1 | False
2 | True - D . 1 | True
2 | False
What is the expected output of the following code?
print(3 * ‘abc’ + ‘xyz’)
- A . 3abcxyz
- B . abcabcxyzxyz
- C . abcabcabcxyz
- D . abcxyzabcxyzabcxyz
What is the expected output of the following code?
- A . 1 | True
2 | False
3 | True
4 | False - B . 1 | False
2 | False
3 | True
4 | True - C . 1 | False
2 | True
3 | True
4 | True - D . 1 | False
2 | True
3 | False
4 | True
What would you insert instead of ???, so that the program prints True to the monitor?
- A . x < y
- B . x is not y
- C . x is y
- D . x != y
What is the expected output of the following code?
- A . 123
- B . 122
- C . 321
- D . 213
What is the expected output of the following code?
- A . 1
- B . 2
- C . 4
- D . 3
What is the data type of x, y, z after executing the following snippet?
- A . int, int, int
- B . x is int, y and z are invalid declarations
- C . int, str, int
- D . int, str, str
What is the expected output of the following code?
x = 2
y = 6
x += 2 ** 3
x //= y // 2 // 3
print(x)
- A . 9
- B . 10
- C . 0
- D . 11
The result of the following division:
- A . cannot be evaluated
- B . is equal to 1.0
- C . is equal to 1
- D . cannot be predicted
What is the expected output of the following code?
- A . 7
- B . The code is erroneous.
- C . 6.0
- D . 7.0
- E . 6
What is the expected output of the following code?
print(‘Mike’ > ‘Mikey’)
- A . False
- B . True
- C . 1
- D . 0
Which of the following is the correct order of operator precedence?
- A . Exponents –
Unary positive, negative, not –
Parentheses –
Multiplication and Division –
Addition and Subtraction –
And - B . Parentheses –
Exponents –
Unary positive, negative, not –
Addition and Subtraction –
Multiplication and Division –
And - C . Parentheses –
Exponents –
Unary positive, negative, not –
Multiplication and Division –
Addition and Subtraction –
And - D . Exponents –
Unary positive, negative, not –
Multiplication and Division –
Addition and Subtraction –
And –
Parentheses
What is the result of the following operation?
- A . 2.0
- B . 11.0
- C . The operation is illegal in Python
- D . 2
Consider the following code.
Which statement will print True to the monitor? (Choose two.)
- A . print(languages == more_languages)
- B . print(languages is more_languages)
- C . print(more_languages is extra_languages)
- D . print(languages is extra_languages)
Which expression evaluates to 7?
- A . 9%3+7
- B . 9-3*7
- C . 9//3-7
- D . 9/3*7
The // operator:
- A . performs integer division
- B . performs regular division
- C . does not exist
Which of the following statements are correct? (Choose two.)
- A . 7 + False evaluates to False
- B . True or False evaluates to True
- C . True + 1 evaluates to 2
- D . True and False evaluates to True
- E . type(”) returns <class ‘bool’>
What is the output of the following snippet?
- A . 25.0
- B . The snippet will cause an execution error.
- C . 17.0
- D . 17
What is the expected output of the following code?
- A . 1 | False
2 | True
3 | False
4 | True - B . 1 | False
2 | True
3 | True
4 | True - C . 1 | False
2 | True
3 | True
4 | False - D . 1 | False
2 | False
3 | True
4 | True
Evaluate the following Python arithmetic expression:
(3*(1+2) **2-(2**2) *3)
What is the result?
- A . 13
- B . 3
- C . 69
- D . 15
What value will be assigned to the x variable?
- A . 1
- B . False
- C . True
Consider the following code.
What does the second assignment do?
- A . It shortens the list.
- B . It reverses the list.
- C . It doesn’t change the list.
- D . It extends the list.
An operator able to check whether two values are equal, is coded as:
- A . ==
- B . ===
- C . is
- D . =
What will be the output of the following snippet?
- A . 00
- B . 11
- C . 01
- D . 10
What is the expected output of the following code?
- A . 2
- B . 0
- C . 1
- D . 3
Consider the following code.
x = oat (‘23.42’)
Which of the following expressions will evaluate to 2?
- A . int(x) + False
- B . bool(x) + True
- C . str(x)
- D . bool(x)
What is the expected output of the following code?
print (1 // 2)
- A . 0.5
- B . 0.0
- C . None of the above.
- D . 0
What is the expected output of the following code?
- A . 1 | True
2 | True
3 | False
4 | False - B . 1 | True
2 | False
3 | False
4 | False - C . 1 | True
2 | False
3 | False
4 | True - D . 1 | True
2 | False
3 | True
4 | False
The expression:
‘mike’ > ‘Mike’
is
- A . erroneous
- B . true
- C . false
You are writing a Python program that evaluates an arithmetic formular.
The formular is described as b equals a multiplied by negative one, then raised to the second power, where a is the value that will be input and b is the result. a = eval (input (‘Enter a number for the equation: ‘))
Which of the following is a valid expression for the given requirement?
- A . b = (-a) ** 2
- B . b = (a-) ** 2
- C . b = (a) ** -2
- D . b = -(a) ** 2
What is the expected output of the following code?
print (2 ** 3 ** 2 ** 1)
- A . 64
- B . 16
- C . 128.0
- D . The code is erroneous.
- E . 16.0
- F . 512
Which of the following code snippets will print True to the monitor? (Choose two.)
A )
B )
C )
D )
E )
- A . Option A
- B . Option B
- C . Option C
- D . Option D
- E . Option E
What value will be assigned to the x variable?
- A . False
- B . 1
- C . 0
- D . True
The ** operator …
- A . does not exist.
- B . performs fl oating-point multiplication.
- C . performs duplicated multiplication.
- D . performs exponentiation.
Right-sided binding means that the following expression
will be evaluated:
- A . from right to left
- B . in random order
- C . from left to right
What is the expected output of the following code?
print (type (1 / 2))
- A . <type ‘double’>
- B . <type ‘int’>
- C . <type ‘number’>
- D . <type ‘tuple’>
- E . <type ‘ oat’>
What is the expected output of the following code?
- A . 01
- B . 10
- C . The code is erroneous.
- D . 00
- E . 11
What is the output of the following code?
- A . 2x
- B . 22
- C . The program will cause an error.
- D . 4
What is the output of the following snippet if the user enters two lines containing 3 and 6 respectively?
- A . 333333
- B . 18
- C . 36
- D . 666
What is the expected output of the following code?
- A . The code is erroneous.
- B . TRUE
- C . FALSE
- D . None of the above.
What is the expected output of the following code if the user enters 2 and 4?
- A . 1.0
- B . 4.0
- C . 2.0
- D . 0.0
What is the expected output of the following code?
x = 4.5
y = 2
print (x // y)
- A . 2.5
- B . 2
- C . 2.25
- D . 2.0
The digraph written as #! is used to:
- A . tell an MS Windows OS how to execute the contents of a Python le.
- B . tell a Unix or Unix-like OS how to execute the contents of a Python le.
- C . create a docstring.
- D . make a particular module entity a private one.
What are the four fundamental elements that make a language?
- A . An alphabet, a lexis, a syntax, and semantics
- B . An alphabet, morphology, phonetics, and semantics
- C . An alphabet, a lexis, phonetics, and semantics
- D . An alphabet, phonetics, phonology, and semantics
What do you call a tool that lets you launch your code step-by-step and inspect it at each moment of execution?
- A . An editor
- B . A debugger
- C . A console
What will be the output of the following code snippet?
- A . 12
- B . 22
- C . 11
- D . 21
What is the expected output of the following code?
- A . 121
- B . 212
- C . 112
- D . 122
Python is an example of:
- A . a machine language
- B . a natural language
- C . a high-level programming language
What is the expected output of the following code?
- A . 0
- B . 1
- C . The code is erroneous.
- D . 2
Which of the following variable names are illegal? (Choose two.)
- A . True
- B . true
- C . and
- D . TRUE
What is CPython?
- A . It’s a programming language that is a superset of the C language, designed to produce Python-like performance with code written in C.
- B . It’s a default, reference implementation of the Python language, written in C.
- C . It’s a programming language that is a superset of the Python, designed to produce C-like performance with code written in Python.
- D . It’s a default, reference implementation of the C language, written in Python.
Which of the following variable names is illegal?
- A . In
- B . IN
- C . in_
- D . in
What is the default value of encoding in the string function encode()?
- A . qwerty
- B . ascii
- C . utf-16
- D . utf-8
What is machine code?
- A . A medium-level programming language consisting of the assembly code designed for the computer processor
- B . A low-level programming language consisting of binary digits/bit that the computer reads and understands
- C . A high-level programming language consisting of instruction lists that humans can read and understand
- D . A low-level programming language consisting of hexadecimal digits that make up high-level language instructions
The pyc fi le contains …
- A . a Python interpreter.
- B . Python source code.
- C . compiled Python bytecode.
- D . a Python compiler.
Select the true statements: (Choose two.)
- A . You can use keywords as variable names in Python
- B . You can use keywords as function names in Python
- C . You cannot use keywords as variable names in Python
- D . You cannot use keywords as function names in Python
The escape character owes its name to the fact that it:
- A . cannot be caught due to its high speed
- B . escapes from source les into the computer memory
- C . changes the meaning of the character next to it