我正在尝试翻译此伪代码,但无法准确翻译。特别是,我似乎无法弄清楚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))
宝慕林4294392
相关分类