繁体   English   中英

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

[英]What does “real” in pseudocode indicate?

我正在尝试翻译此伪代码,但无法准确执行。 特别是,我似乎无法弄清楚这里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))

某些语言使用术语“实数”代替“浮点数”等。因此,在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 ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM