mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27: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):
|
||||
sum = 0
|
||||
n = 0
|
||||
for x in nums:
|
||||
sum += x
|
||||
n += 1
|
||||
avg = sum / n
|
||||
avg = sum / len(nums)
|
||||
print(avg)
|
||||
return avg
|
||||
|
||||
def main():
|
||||
average([2, 4, 6, 8, 20, 50, 70])
|
||||
|
|
Loading…
Reference in New Issue
Block a user