我准确地做到了这一点 . 特别是,我似乎无法弄清 real
这意味着什么 . 这是伪代码:
Function Real average(Real values[], Integer size)
Declare Real total = 0.0
Declare Integer counter = 0
While counter < size
Set total = total + values[counter]
Set counter = counter + 1
End While
Return total / size
End Function
Declare Real scores[6] = 90, 80, 70, 100, 60, 80
Display average(scores, 6)
这就是我想出来的:
def average(values[], int(size))
total = 0.0
counter = 0
while counter < size:
total = total + values[counter]
counter = counter + 1
return total / size
scores[6] = 90, 80, 70, 100, 60, 80
print(average(scores, 6))
1 回答
有些语言使用术语“真实”代替“浮动”等 . 因此,在Python中,使用这段代码可以将其排除在外 . ..但除此之外,你的代码还有一些问题 . 例如,你只是想要
然后给出平均“得分”和6
像这样
虽然显然没有必要这样做,但我认为你只是在学习Python ......