简体   繁体   English

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

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

I'm trying to translate this pseudocode and can't do it accurately. 我正在尝试翻译此伪代码,但无法准确执行。 In particular, I can't seem to figure out what real here means. 特别是,我似乎无法弄清楚这里real含义。 This is the pseudocode: 这是伪代码:

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)

And this is what I've come up with: 这就是我想出的:

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))

Some languages use the term "real" in place of "float" etc. Therefore, in Python, with this bit of code you can leave it out. 某些语言使用术语“实数”代替“浮点数”等。因此,在Python中,通过这段代码,您可以将其省略。 ..but there are a few things wrong with your code other than that. ..但除此之外,您的代码还有一些其他问题。 For example you just want 例如你只想要

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

then just give average "scores" and 6 然后只给出平均“分数”和6

Like this 像这样

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))

Whilst clearly it is not necessary to do this in this way, I presume you are just learning Python... 虽然显然没有必要以这种方式执行此操作,但我想您只是在学习Python ...

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

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