Week 2 Assignment (Part 1 - Questions)
22. October 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?
[[[]]]
❌[] [] []
❌[]
✅[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?
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.