gpt4 book ai didi

python - 做数学时出现问题

转载 作者:行者123 更新时间:2023-11-28 20:19:03 26 4
gpt4 key购买 nike

我有以下代码,但是当我运行它时,我得到类型“NoneType”。我指出我的“求和”变量是具有 Nonetype 的变量,这是为什么呢?我该如何改变它?我试着制作成一个 float() 但它对我不起作用。欢迎任何见解。

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def grades_sum(scores):
total = 0
for item in scores:
total = item + total
print total

grades_sum(grades)


def grade_average(grades):
summation = grades_sum(grades)
average = summation / float(len(grades))
return average

print grade_average(grades)

最佳答案

改打印为返回。

def grades_sum(scores):
total = 0
for item in scores:
total = item + total
return total

关于python - <type 'NoneType'> 做数学时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35304964/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com