Python Essentials 1 – Module 2 Test Answers
Python Essentials 1 Module 2 Completion – Module Test Quiz Answers
PE1: Module 2. Python Data Types, Variables, Operators, and Basic I/O Operations
1. The \n digraph forces the print() function to:
- duplicate the character next to the digraph
- break the output line
- stop its execution
- output exactly two characters:
\
andn
2. The meaning of the keyword parameter is determined by:
- its position within the argument list
- its connection with existing variables
- the argument’s name specified along with its value
- its value
3. The value twenty point twelve times ten raised to the power of eight should be written as:
- 20.12E8
- 20.12*10^8
- 20.12E8.0
- 20E12.8
4. The 0o prefix means that the number after it is denoted as:
- decimal
- octal
- binary
- hexadecimal
If an integer number is preceded by 0x or 0X, it will be treated as a hexadecimal value. For example: 0x246 is a hexadecimal number with a decimal value equal to 582.
Finally, if an integer number is preceded by 0b or 0B, it will be treated as a binary value. For example: 0b1111 is a binary number with a decimal value equal to 15.
5. The ** operator:
- does not exist
- performs exponentiation
- performs duplicated multiplication
- performs floating-point multiplication
6. The result of the following division:
1 / 1
- cannot be predicted
- cannot be evaluated
- is equal to 1.0
- is equal to 1
The // operator, called the floor division operator, performs a similar operation, but rounds down the result and returns an integer number.
7. Which of the following statements are true? (Select two answers)
- The right argument of the % operator cannot be zero.
- The result of the / operator is always an integer value.
- The ** operator uses right-sided binding.
- Addition precedes multiplication.
The ** operator uses right-sided binding, which means the expression 2**2**3 is evaluated from right to left: 2**3 = 8, and 2**8 = 256.
8. Left-sided binding determines that the result of the following expression:
1 // 2 * 3
is equal to:
- 0.0
- 0
- 0.16666666666666666
- 4.5
9. Which of the following variable names are illegal? (Select two answers)
- and
- true
- True
- TRUE
10. The print() function can output values of:
- any number of arguments (excluding zero)
- not more than five arguments
- any number of arguments (including zero)
- just one argument
print()
), three arguments (e.g. print("one", "two", "three"
), or three thousand three hundred thirty three… (though we haven’t actually checked it!).
11. What is the output of the following snippet?
x = 1 y = 2 z = x x = y y = z print(x, y)
- 2 1
- 1 1
- 1 2
- 2 2
– the value 1 is assigned to variable x, and variable x is initiated (so x = 1)
– the value 2 is assigned to variable y, and variable y is initiated (so y = 2)
– the value assigned to variable x is assigned to variable z, and variable z is initiated (so z = 1)
– the x variable is assigned the value which is assigned to variable y (so x = 2)
– the y variable is assigned the value which is assigned to variable z (so y = 1)
– the values ssigned to variables x and y are now printed, giving the following output: 2 1
(note: the print() function separates the outputted values with a whitespace)
12. What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively?
x = input() y = input() print(x + y)
- 4
- 24
- 2
- 6
the input() function reads the arguments entered by the user (2 and 4 respectively) and converts them to strings,
variables x and y are assigned the strings inputted by the user,
the print() function outputs the result of the concatenation operation to the screen (the process of adding/merging strings): “2” + “4”; the + operator adds a string to another string, and outputs 24.
13. What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively?
x = int(input()) y = int(input()) x = x // y y = y // x print(y)
- 8.0
- the code will cause a runtime error
- 2.0
- 4.0
– the x variable is assigned the integer value of 2 (2 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
– the y variable is assigned the integer value of 4 (4 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
– an operation is performed resulting in the x variable being assigned the value of 0 (2 // 4=0)
– an operation is being performed, but a ZeroDivisionException is raised, because the // operator cannot accept 0 as its right operand. The program is terminated.
14. What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively?
x = int(input()) y = int(input()) x = x / y y = y / x print(y)
- the code will cause a runtime error
- 2.0
- 8.0
- 4.0
the x variable is assigned the integer value of 2 (2 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
the y variable is assigned the integer value of 4 (4 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
an operation is performed resulting in the x variable being assigned the value of 0.5 (2 / 4 = 0.5)
an operation is performed resulting in the y variable being assigned the value of 8.0 (4 / 0.5 = 8.0)
the value assigned to the y variable (8.0) is printed to the screen.
15. What is the output of the following snippet if the user enters two lines containing 11 and 4 respectively?
x = int(input()) y = int(input()) x = x % y x = x % y y = y % x print(y)
- 1
- 2
- 3
- 4
the x variable is assigned the integer value of 11 (11 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
the y variable is assigned the integer value of 4 (4 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
an operation is performed resulting in the x variable being assigned the value of 3 (11 % 4 = 3)
an operation is performed resulting in the x variable being assigned the value of 0 (3 % 11 = 0)
an operation is performed resulting in the y variable being assigned the value of 1 (4 % 3 = 1)
the value assigned to the y variable (1) is printed to the screen.
16. What is the output of the following snippet if the user enters two lines containing 3 and 6 respectively?
x = input() y = int(input()) print(x * y)
- 333333
- 666
- 36
- 18
the x variable is assigned the value of “3” (3 is inputted by the user and converted to a string by the input() function)
the y variable is assigned the value of 6 (6 is inputted by the user, converted to a string by the input() function, and then converted to an integer by the int() function)
the print() function outputs the result of the following string multiplication: “3” * 6, that is 333333
17. What is the output of the following snippet?
z = y = x = 1 print(x, y, z, sep='*')
- x y z
- 1 1 1
- x*y*z
- 1*1*1
the variables z, y, and x are declared and initialized, and the value 1 is assigned to each of them by using the mechanism of assigning the same value to multiple variables,
the values assigned to the three variables are printed to the screen and separated by the * symbol using the sep keyword argument.
18. What is the output of the following snippet?
y = 2 + 3 * 5. print(Y)
- the snippet will cause an execution error
- 17
- 25.
- 17.0
19. What is the output of the following snippet?
x = 1 / 2 + 3 // 3 + 4 ** 2 print(x)
- 8
- 17
- 17.5
- 8.5
first, the 4 ** 2 expression is evaluated with 16 as the result,
second, the 1 / 2 expression is evaluated with 0.5 as the result,
third, the 3 // 3 expression is evaluated with 1 as the result,
finally, the three values are added (0.5 + 1 + 16), and the resulting value (17.5) is assigned to the x variable and printed to the screen.
20. What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively?
x = int(input()) y = int(input()) print(x + y)
- 4
- 2
- 24
- 6