Skip to content

Commit 12a16d6

Browse files
lordsarcasticpoyea
authored andcommitted
Update average.py (#908)
Reduced lines of code and extra processing on the line: n += 1
1 parent a99acae commit 12a16d6

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

maths/average.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
def average(nums):
22
sum = 0
3-
n = 0
43
for x in nums:
54
sum += x
6-
n += 1
7-
avg = sum / n
5+
avg = sum / len(nums)
86
print(avg)
7+
return avg
98

109
def main():
1110
average([2, 4, 6, 8, 20, 50, 70])

0 commit comments

Comments
 (0)