Translate to Traditional Chinese (δΈ­ζ–‡):

<< Prev   🏠 A B C D E F G Next >>


D.py - AVGDIV


Your task is to write a function average_divisible_by_7(nums) that calculates the average of all numbers in a given list nums that are divisible by 7.

NOTE: If there are no numbers divisible by 7, return 0.0.

Input:A list of integers nums.
Output:Return the average of all numbers in the list that are divisible by 7.

Example 1:
Input: nums = [7, 14, 20, 21, 28]
Return: 17.5
Explanation: (7 + 14 + 21 + 28) / 4 = 17.5
Example 2:
Input: nums = [1, 2, 3, 4, 5, 6]
Return: 0.0
Explanation: None of the numbers in the list are divisible by 7, so the average is 0.0.
Example 3:
Input: nums = [7, 15, 35, 49, 50]
Return: 30.33
Explanation: (7 + 35 + 49) / 3 = 30.3333
Example 4:
Input: nums = [63, 10, 21]
Return: 42.0
Explanation: (63 + 21) / 2 = 42.0


<< Prev   🏠 A B C D E F G    Next >>