Final Exam (Part 1 - Questions)
22. October 2024
Question 1
What is the result of the following operation 9 % 4
?
2.25
❌2
❌2.0
❌1
✅Question 2
What is the value of variable b
after the execution of the following statements?
10
✅5
❌(5, 10)
❌15
❌Question 3
The result of which of the following mathematical operations has the data type integer?
2.0 + 3
❌9 ** 0.5
❌2 // 3
✅2 / 3
❌2 % 3
✅Question 4
What is the result of the following statement?
12 34
❌"12", "34"
❌1234
✅46
❌Question 5
What is the value of a
after the following statements have been executed?
"1234"
❌"1230"
✅"127"
❌"123"
❌Question 6
According to the following code, what is the drink?
Whiskey
❌Milk
❌Beer
❌Cola
✅Question 7
Which of the following numbers assigned to the variable a
makes the following expression True?
Note: There are 2 correct answers to this question.
17
❌18
❌14
✅16
✅15
❌Question 8
Which of the following statements about lists are correct?
Note: There are 3 correct answers to this question.
Lists can contain elements of all data types. That means there can be lists of integers or list of strings.
✅Lists can be multiplied with integers. The result is again a list.
✅All elements within a list must have the same data type.
❌The keyword "in" is used to check if a given element is part of a list.
✅The elements of a list are separated by semicolons ";".
❌Question 9
What is the content of variable list1
after the following statement has been executed?
[1, 3, 5, 2, 4, 6]
✅[[1, 3, 5], [2, 4, 6]]
❌[1, 2, 3, 4, 5, 6]
❌[3, 7, 11]
❌Question 10
What is the value of variable list1
after the following statements have been executed?
[1, 1, 1, 2, 3]
❌[1, 1, 3]
❌[1, 1, 1, 2, 2, 3]
✅[1, 1, 2, 2, 2, 3]
❌Question 11
What is the value of x
after the following statements have been executed?
9
❌1
❌4
✅7
❌Question 12
Which sequence is generated by the following range? range(1, 9, 2)
2, 4, 6, 8
❌1, 3, 5, 7, 9, 11, 13, 15
❌1, 3, 5, 7, 9
❌1, 3, 5, 7
✅Question 13
What is the value of variable list2
after the following statements have been executed?
[4, 2, 0]
✅[0, 2, 4]
❌[3, 1]
❌[6, 4, 2, 0]
❌Question 14
What is the value of variable a
after the following statements have been executed?
(1980, "July", 31)
Error
❌Potter
❌1980
✅Question 15
What is the effect of the following statements?
As the key is already available, this code runs into an error.
❌The key-value pair " "Peter" : 234 " is added to the dictionary.
❌The key-value pair " "Peter" : 123 " is replaced by " "Peter " : 234 "
✅As the key is already available, the dictionary is unchanged.
❌Question 16
What is the result of the following statements?
Variable "a" contains the value " "Hermione" "
❌Variable "a" contains the value " "Harry" "
✅Index Error
❌Key Error
❌Question 17
Which of the following statements about the while loop are correct?
Note: There are 3 correct answers to this question.
while loops can end up in infinite loops.
✅while loops should be preferred over for loops.
❌If the iteration is to be done over a sequence, for loops are preferred. If it is not clear how many iterations are required, then a while loop is (often) the better choice.
✅while loops execute the while block (that is, the conditional statements belonging to the loop) at least once.
❌The while block (that is, the conditional statements belonging to the loop) must contain at least one statement.
✅Question 18
What is the value of variable a
after the following code has been executed?
65
❌54
✅66
❌55
❌Question 19
Which of the following statements about the modes used to open a file are correct?
Note: There are 3 correct answers to this question.
In mode "r", the file must exist. If an attempt is made to access a file that is not available, the FileNotFoundError is triggered.
✅In mode "r+", it is possible to read data from a file, but also to write data to the file.
✅If data is written to a file that is opened in mode "r", an error is triggered.
✅A file opened in mode "r+" has first to be read. In a second step, data can be written to the file. A file opened in mode "w+" must first have data written to the file before data can be read.
❌In mode "w+", an existing file will be opened.
❌Question 20
Which of the following statements about reading from a file are correct?
Note: There are 3 correct answers to this question.
It is possible to read the complete file into a list in one go, without a for loop, using the method ".readlines()"
✅Files are organized sequentially, therefore a for loop can be used to iterate over the lines of a file.
✅As files are organized sequentially, they can easily be converted into a list, as a list is a sequence type as well.
✅If a file is read with ".readlines()", it is not necessary to close it at the end of the program.
❌If a file is read from the beginning to the end, the read cursor is automatically positioned at the beginning of the file again.
❌Question 21
Which of the following statements about f-strings are correct?
Note: There are 3 correct answers to this question.
It is possible to add additional information into the braces, which supports the alignment of the output.
✅To indicate that a string should be treated as an f-string, an "f" simply has to be placed before the string.
✅When using an f-string, curly braces "{ }" can be used. Variables or function calls can be placed within these braces.
✅Using f-strings, the programmer has the opportunity to specify the layout. For example, the output could be in different colors, or bold, or italic.
❌f-strings have been available in Python since version 3.0.
❌Question 22
What is the result of the following statement?
['Yesterday,', 'Let', 'it', 'be,', 'Help,', 'Something']
✅"Yesterday, Let it be, Help, Something"
❌"Yesterday", " Let it be", " Help", " Something"
❌['Yesterday', 'Let it be', 'Help', 'Something']
❌Question 23
Which of the following are built-in-functions in Python?
Note: There are 2 correct answers to this question.
.strip()
❌.isdecimal()
❌int()
✅for
❌print()
✅Question 24
Which of the following statements about the syntax of functions in Python are correct?
Note: There are 2 correct answers to this question.