Week 2 Assignment (Part 1 - Questions)

05. December 2024

Question 1

Which of the following statements about lists are correct?

Note: There are 3 correct answers to this question.


The elements within a list are always sorted by size.
Lists consist of several elements or items.
Lists can be empty, in other words, they contain no elements.
It is possible to add two lists. The result will again be a list.
You can multiply two lists. The result will be a list.

Question 2

What is the content of variable list1 after the following statements have been executed?

week2 assignment f2

[[[]]]
[] [] []
[]
[3]

Question 3

Which of the following statements about indices are correct?

Note: There are 3 correct answers to this question.


For each element in the list, there is exactly one index.
Indices are always of data type integer.
Indices can be positive and negative.
Using an index bigger than the length of the list leads to an error.
The index -0 is not defined.

Question 4

Which of the following statements about functions and methods for lists are correct?

Note: There are 2 correct answers to this question.


The function "min()" returns the smallest element of a list. If the list contains elements of different data types, an automatic casting of the data types takes place for all elements.
The function "len()" returns the length of the list, that is, the number of elements the list contains.
The method ".append()" adds a new item at the end of the list.
The method ".pop()" returns the last element of a list. The list remains unchanged.
The method ".remove()" deletes all occurrences of the parameter in the parentheses contained in the list.

Question 5

What is the value of the variable x after the following statements have been executed?

week2 assignment f5

10
1
4
24

Question 6

Which of the following statements about loops are true?

Note: There are 3 correct answers to this question.


Because strings are not sequences, for loops cannot iterate over strings.
for loops are well suited to iterate over sequences.
In each iteration of the for loop, the next element of the sequence is assigned to the sequence variable.
for loops and if-elif-else constructs can be combined.
for loops iterating over an empty sequence (for example, an empty list) will result in an error.

Question 7

Which of the following statements about ranges are correct?

Note: There are 2 correct answers to this question.


Using a range, a sequence of characters can be created.
Using a range, a sequence of numbers can be created.
The first parameter of the range is the starting point of the created sequence, the second parameter is its endpoint. The first parameter belongs to the sequence, the second parameter does not.
If the second parameter of the range is negative, the created sequence is decreasing.
Ranges create sequences of integers. These sequences can be in increasing, in decreasing, or in an arbitrary order.

Question 8

Which sequence is created by the following range? range(10, 1)


9, 8, 7, 6, 5, 4, 3, 2, 1
Error
10, 9, 8, 7, 6, 5, 4, 3, 2
Empty sequence: there is no integer in the sequence

Question 9

What is the value of variable list2 after the following statements have been executed?

week2 assignment f9

[0, 0.5, 1, 1.5, 2]
[0, 1, 2, 3, 4]
[0, 2, 4]
[1, 3]

Question 10

What is the value of list2 after the following statements have been executed?

week2 assignment f10

['Liverpool FC', 'Chelsea FC']
[6, 2]
[['Liverpool FC', 6], ['Chelsea FC', 2]]
[ ]

< Previous unit | Next unit > | Course Overview