0 out of 464 challenges solved
Write a Python function `multiply_and_divide(numbers)` that takes a list of numbers as input. The function should multiply all the numbers in the list together and then divide the result by the length of the list. Return the final result. #### Example Usage ```python [main.nopy] print(multiply_and_divide([8, 2, 3, -1, 7])) # Output: -67.2 print(multiply_and_divide([-10, -20, -30])) # Output: -2000.0 print(multiply_and_divide([19, 15, 18])) # Output: 1710.0 ``` #### Constraints - The input list will always contain at least one number. - The numbers can be integers or floats.
def multiply_and_divide(numbers): """ Multiplies all numbers in the list and divides the result by the length of the list. Args: numbers (list): A list of numbers (int or float). Returns: float: The result of the operation. """ # Initialize the total product to 1 total_product = 1 # Iterate through the list and multiply the numbers for num in numbers: total_product *= num # Divide the total product by the length of the list result = total_product / len(numbers) return result