Hi Folks,
Could you please help me to understand how to create new variable that sums the array
create another variable that sums the array arg_numbers. Finish the line that starts with numbs_sum = by calculating the sum of all of numbers in the argument.
1. numbers = [13, 5102, 45, 2301.40, 203, 1502, 3]
numbers_sum = sum(numbers)
if len(numbers) >= 1:
print(numbers_sum/len(numbers))
else:
print(0)
If this is your data:
numbers = [13, 5102, 45, 2301.40, 203, 1502, 3]
You call the function
sum
, which returns the sum and assign it to a name.
total = sum(numbers)
total
is now the
sum
of
numbers
.
I can be a
float
, but in your case it's an
int
because all input values are integers.
Then you can print the value:
print("Sum of number is:", total)
https://docs.python.org/3/library/functions.html#sum
For statistics, you could use:
https://docs.python.org/3/library/statistics.html
[quote='DeaD_EyE' pid='126814' dateline='1601033064']
If this is your data:
numbers = [13, 5102, 45, 2301.40, 203, 1502, 3]
You call the function
sum
, which returns the sum and assign it to a name.
total = sum(numbers)
total
is now the
sum
of
numbers
.
I can be a
float
, but in your case it's an
int
because all input values are integers.
Then you can print the value:
print("Sum of number is:", total)
Hi Da Bishop,
Thanks for your prompt response the real query as below.
numbers = [13, 5102, 45, 2301.40, 203, 1502, 3]
numbers_sum = sum(numbers)
if len(numbers) >= 1:
print(numbers_sum/len(numbers))
else:
print(0)
# Complete the mean function
[python]def mean(_____):
numbs_sum = ______
if ________:
return _______
else:
return _______
# Test code - Do not change anything below this line
print(mean(numbers))
step 1:-
Fill in the blank in the mean function by providing the argument, which we will call - arg_numbers.
def mean(arg_numbers):
step2 :-
Now let's create another variable that sums the array arg_numbers. Finish the line that starts with numbs_sum = by calculating the sum of all of numbers in the argument.
numbs_sum = ______
so I struck in this step 2 level.