# Sample list of numbers
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# Use list comprehension to create a new list containing even numbers
even_numbers = [num for num in numbers if num % 2 == 0]
# Calculate the sum of even numbers using the sum() function
sum_even_numbers = sum(even_numbers)
# Print the original list, even numbers, and their sum
print("Original List:", numbers)
print("Even Numbers:", even_numbers)
print("Sum of Even Numbers:", sum_even_numbers)
import math
def worst_case_binary_search_iterations(array_length):
"""
Calculate the worst-case number of iterations for binary search
in an array of given length.
Args:
array_length (int): Length of the array.
Returns:
int: Worst-case number of iterations.
"""
# Calculate the worst-case number of iterations using log base 2
iterations = math.ceil(math.log2(array_length))
return iterations
# Example usage for an array of length 20
array_length = 20
worst_case_iterations = worst_case_binary_search_iterations(array_length)
print("Worst Case Number of Iterations for Binary Search in an Array of Length 20:", worst_case_iterations)
Question #3
Answer: A
Explanation: Option A multiplies every item in myList
by 2.