mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-19 00:37:02 +00:00
Update average.py (#908)
Reduced lines of code and extra processing on the line: n += 1
This commit is contained in:
parent
a99acae32d
commit
12a16d63b7
|
@ -1,11 +1,10 @@
|
||||||
def average(nums):
|
def average(nums):
|
||||||
sum = 0
|
sum = 0
|
||||||
n = 0
|
|
||||||
for x in nums:
|
for x in nums:
|
||||||
sum += x
|
sum += x
|
||||||
n += 1
|
avg = sum / len(nums)
|
||||||
avg = sum / n
|
|
||||||
print(avg)
|
print(avg)
|
||||||
|
return avg
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
average([2, 4, 6, 8, 20, 50, 70])
|
average([2, 4, 6, 8, 20, 50, 70])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user