Coding Quiz 03

Python Coding Quiz

Python Coding Quiz

Answer the coding questions below by selecting all applicable options:

Time Remaining: 10:00

1. Which syntax is correct for defining a function in Python?

A) function greet() B) def greet(): C) func greet(): D) create greet()

2. Which of the following is the correct way to create a list in Python?

A) my_list = [1, 2, 3] B) my_list = list[1, 2, 3] C) my_list = [1, 2, 3,] D) my_list = (1, 2, 3)

3. Which of the following statements will correctly access the last element of a list called my_list? (Select all that apply)

A) my_list[-1] B) my_list[len(my_list) - 1] C) my_list.pop() D) my_list[0]

4. Which of the following syntax will create a dictionary in Python?

A) {"name": "Alice", "age": 30} B) dict(name="Alice", age=30) C) [("name", "Alice"), ("age", 30)] D) {"Alice": 30, 40}

5. How would you iterate over each item in a list called items in Python?

A) for i in items: B) for item in items: C) while item in items: D) items.forEach(item)

6. Which of the following code will create a set in Python?

A) set([1, 2, 3]) B) {1, 2, 3} C) {1: "one", 2: "two", 3: "three"} D) set()

7. How can you concatenate two strings "Hello" and "World" in Python?

A) "Hello" + "World" B) "Hello".concat("World") C) join("Hello", "World") D) "Hello" - "World"

8. How do you slice a list my_list to get elements from index 1 to 3 (inclusive of 1, exclusive of 3)?

A) my_list[1:3] B) my_list[1, 3] C) my_list(1:3) D) my_list[1, 2]

9. How do you start an if statement in Python?

A) if x > y then: B) if x > y: C) if (x > y) D) if x > y {

10. Which keyword is used to define a class in Python?

A) class B) define C) create D) object