mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-20 13:23:13 -07:00
Create calculate_average
This commit is contained in:
parent
c4cb05fe40
commit
aab6692bdd
1 changed files with 11 additions and 0 deletions
11
calculate_average
Normal file
11
calculate_average
Normal file
|
@ -0,0 +1,11 @@
|
|||
def calculate_average(numbers):
|
||||
total = 0
|
||||
for number in numbers:
|
||||
total += number
|
||||
# 小bug: 错误地使用了整数除法,这在Python 3中会导致精度丢失
|
||||
average = total // len(numbers)
|
||||
return average
|
||||
|
||||
# 示例
|
||||
numbers = [10, 20, 30, 40, 50]
|
||||
print(f"Average: {calculate_average(numbers)}")
|
Loading…
Add table
Add a link
Reference in a new issue