Artificial Intelligence
Please fill the required field.

fix this code : def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) صحح الكود التالي : def calculate_average(numbers): total_sum = 0 for num in numbers: total_sum = total_sum + number


Here are the corrections needed for the provided code: 1. There is a typo in the variable name inside the loop; it should be `num` instead of `number`. 2. The variable `nums` is undefined; it should be `numbers` when calling the `calculate_average` function. Here's the corrected code: ```python def calculate_average(numbers): total_sum = 0 for num in numbers: total_sum = total_sum + num # Changed 'number' to 'num' average = total_sum / len(numbers) return average numbers = [10, 20, 30, 40, 50] print("The average is:", calculate_average(numbers)) # Changed 'nums' to 'numbers' ``` Now the code should work correctly and calculate the average of the list of numbers.