Python Final MCQs
Python Final MCQs
python
Copy code
result = a * b
return result
x=3
y=4
sum_result = add_numbers(x, y)
print("Sum:", sum_result)
a) The add_numbers function should use the addition operator (+) instead of the multiplication operator (*).
d) The add_numbers function should return the sum of a and b instead of their product.
Answer: d
python
Copy code
def calculate_area(radius):
area = calculate_area(r)
print("Area:", area)
a) The input function returns a string, and it should be converted to a float for the calculation.
python
Copy code
print(a + b)
result = add_numbers(3, 4, 5)
Answer: b
python
Copy code
return a * b
result = multiply(3)
Answer: b
Copy code
numbers = [1, 2, 3, 4, 5]
for i in range(6):
print(numbers[i])
Answer: a
python
Copy code
return a / b
result = divide(10, 0)
Answer: a
python
Copy code
def process_data(data):
result = data * 2
return result
input_data = input("Enter data: ")
output = process_data(input_data)
Answer: a
python
Copy code
return a + b
Answer: a
python
Copy code
def square(x):
return x ** 2
numbers = [1, 2, 3, 4, 5]
squared_numbers = square(numbers)
Answer: c
python
Copy code
def find_average(numbers):
average_grade = find_average(grades)
Answer: c
python
Copy code
def print_even_numbers(numbers):
if num % 2 == 0:
print(num)
numbers = [1, 2, 3, 4, 5, "6"]
print_even_numbers(numbers)
Answer: c
DEBUGING
result = a * b
return result
x=3
y=4
sum_result = add_numbers(x, y)
print("Sum:", sum_result)
a) The add_numbers function should use the addition operator (+) instead of the multiplication operator (*).
d) The add_numbers function should return the sum of a and b instead of their product.
Ans: d
result = a - b
return abs(result)
value_a = '10'
value_b = 5
Ans: c
def process_numbers(numbers):
result = process_numbers(data)
a) The code will run successfully, returning the sum of the valid numbers.
Ans: b
def process_dict(dictionary):
processed_dict = process_dict(data_dict)
a) The code will run successfully, returning a dictionary with uppercase string values.
Ans: c
second_list = ['3', 4, 5, 6, 7]
Ans: a