0

Please tell me how to find average of n numbers in python

18th Aug 2021, 12:20 PM
Srajan Gupta
Srajan Gupta - avatar
3 Réponses
+ 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.
18th Aug 2021, 12:32 PM
Artem 🇺🇦
Artem 🇺🇦 - avatar
+ 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)
18th Aug 2021, 3:27 PM
Лев Павлов
Лев Павлов - avatar
+ 1
lst = [put n numbers in here] sum = 0 for x in lst: sum += x average = sum/len(lst)
18th Aug 2021, 3:10 PM
Chloe
Chloe - avatar