Coding Quiz 04

Python Coding Quiz

Python Coding Quiz

Answer the coding questions below by selecting all applicable options:

Time Remaining: 10:00

1. What is the output of the following code?

def calculate_total(a, b):
    return a + b

print(calculate_total(3, 4))
A) 7 B) 34 C) 12 D) Error

2. What will the following code output?

my_list = [1, 2, 3, 4]
print(my_list[-1])
A) 1 B) 4 C) -1 D) IndexError

3. What is the output of the following code?

x = "Hello"
y = x
y += " World"
print(x)
A) Hello World B) Hello C) Error D) None

4. What is the output of this code snippet?

for i in range(5):
    if i == 3:
        break
    print(i)
A) 0 1 2 B) 0 1 2 3 C) 0 1 2 3 4 D) None

5. What will be printed by the following code?

x = [1, 2, 3]
y = x
y.append(4)
print(x)
A) [1, 2, 3] B) [1, 2, 3, 4] C) Error D) None

6. What will be the result of the following code?

x = 5
y = 10
x, y = y, x
print(x, y)
A) 5 10 B) 10 5 C) 5 5 D) 10 10

7. What does the following code output?

my_set = {1, 2, 3}
my_set.add(2)
print(my_set)
A) {1, 2, 3} B) {1, 2, 3, 2} C) {1, 2, 3, 4} D) None

8. What will the following code output?

x = [1, 2, 3]
y = x.copy()
y.append(4)
print(x)
A) [1, 2, 3, 4] B) [1, 2, 3] C) Error D) None

9. What will the following code output?

def func(x=[]):
    x.append(1)
    print(x)

func()
func()
A) [1], [1, 1] B) [1] C) Error D) None

10. What will be the result of the following code?

x = [1, 2]
y = x
y += [3]
print(x, y)
A) [1, 2] [1, 2, 3] B) [1, 2, 3] [1, 2, 3] C) Error D) None