0
Please tell me how to find average of n numbers in python
3 Respuestas
+ 2
Create a for loop (0 to N) and within this loop on every iteration input a number and add it to a variable called, for instance, sum. Then print the sum.
+ 2
There is default sum() function, don’t create variables with such names.
You can put your numbers in list, or use range if they go after each other and then divide their sum by lenght (there are also default function len() ) of the list:
my_list = [1, 3, 8, 2]
average = sum(my_list) / len(my_list)
+ 1
lst = [put n numbers in here]
sum = 0
for x in lst:
sum += x
average = sum/len(lst)