'Computing an average, I need to write a single statement that assigns avg_sales with the average of num_sales1

I need to write a single statement that assigns avg_sales with the average of num_sales1, num_sales2, and num_sales3, Sample output with inputs: 3 4 8, Average sales: 5.00.



Solution 1:[1]

try numpy:

import numpy as np
print(np.average([3, 4, 8]))

output:

5.0

Solution 2:[2]

It says a single statement so

avg_sales = float((num_sales1 + num_sales2 + num_sales3) / 3)

Solution 3:[3]

I have this question on the variable section on WGU C859 intro to Python practice lab. Here is how I did it.

avg_sales = 5

avg_sales = (num_sales1 + num_sales2 + num_sales3) / 3

print('Average sales: {:.2f}'.format(avg_sales))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stefan Schulz
Solution 2 snakecharmerb
Solution 3 Suraj Rao