为了账号安全,请及时绑定邮箱和手机立即绑定

伪代码中的“真实”表示什么?

伪代码中的“真实”表示什么?

慕虎7371278 2021-09-11 18:00:45
我正在尝试翻译此伪代码,但无法准确翻译。特别是,我似乎无法弄清楚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 / sizeEnd FunctionDeclare Real scores[6] = 90, 80, 70, 100, 60, 80Display 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 / sizescores[6] = 90, 80, 70, 100, 60, 80print(average(scores, 6))
查看完整描述

1 回答

?
宝慕林4294392

TA贡献2021条经验 获得超8个赞

某些语言使用术语“real”代替“float”等。因此,在 Python 中,使用这段代码您可以将其省略。..但除此之外,您的代码还有一些问题。例如你只想要


scores=[90,80, 70, 100, 60, 80]

然后只给出平均“分数”和 6


像这样


def average(values ,size):

    total = 0.0

    counter = 0


    while counter < size:

        total = total + values[counter]

        counter = counter + 1


   return total / size


scores = [90, 80, 70, 100, 60, 80]

print(average(scores, 6))

虽然显然没有必要以这种方式执行此操作,但我认为您只是在学习 Python...


查看完整回答
反对 回复 2021-09-11
  • 1 回答
  • 0 关注
  • 229 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信