能告诉我这个伪代码吗? [英] Can you please explain this pseudo-code to me?

查看:84
本文介绍了能告诉我这个伪代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本修订指南(不是家庭作业,只是我试图了解更多)中,有一个关于伪代码和基于它的跟踪表的问题。我无法解释它因为我不理解伪代码,如果你能完全向我解释,我将不胜感激。请注意我是新手,并不知道很多。谢谢。



伪码:



SET列表TO [3,6,9,13, 17,21]

SET发现错误

接收项目来自(整数)键盘

索引从0到长度(列表) - 1 DO

如果项目=列表[索引]那么

SET发现为真

发送'发现'要显示

结束如果

结束



我尝试过:



我重读了它,但全部都是这样;特别是列表,索引和找到的部分(基本上是整个代码)对我来说仍然没有意义。谢谢。

In this revision guide (not homework btw just me trying to learn more) there is a question on a pseudo-code and a trace table based on it. I can't interpret it because I don't understand the pseudo-code, and I would appreciate it if you could explain it to me fully. Please be aware that I am new to this and do not know a lot. Thanks.

Pseudo-code:

SET list TO [3, 6, 9, 13, 17, 21]
SET found TO False
RECEIVE item FROM (INTEGER) KEYBOARD
FOR index FROM 0 TO LENGTH (list) - 1 DO
IF item = list[index] THEN
SET found TO True
SEND 'Found' TO DISPLAY
END IF
END FOR

What I have tried:

I have re-read it, yet all of it; especially the list, index and found part (which is basically the whole code) still doesn't make sense to me. Thanks.

推荐答案

这是一步一步的代码:

Here is this code step by step:
SET list TO [3, 6, 9, 13, 17, 21]

你有一份你要做的事情清单。您要执行某些操作的数字按顺序为3,6,9,13,17和21。

You have a list of things you are going to do something with. The numbers you are going to do something with are 3,6,9,13,17 and 21 in that order.

SET found TO False

设置变量以发信号(标记当你找到了你要找的东西时给你。

Set up a variable to signal (flag) to you when you have found something that you are looking for.

RECEIVE item FROM (INTEGER) KEYBOARD

接受用户的一些输入。它必须是整数(整数),我们将称之为 item



我'我会暂停在这里,因为我认为这是你正在努力的一点。

我们在开头设置的那个列表中的每个数字在列表中都有一个位置。

Accept some input from the user. It must be an integer (whole number) and we are going to call it "item"

I'm going to pause here as I think this is the bit that you are struggling with.
Each number in that list we set up at the beginning has a "position" in the list.

3 is 1st, 6 is 2nd, 9 is 3rd etc.

我们将该位置称为index。在许多编程语言中,索引从 0 开始。即

We refer to that position as it's "index". In many programming languages that index starts at 0. I.e.

3 is 1st, has index 0
6 is 2nd, has index 1
9 is 3rd, has index 2
...
21 is last, has index 5

该列表还有一个长度的概念 - 或列表中的条目数。在这种情况下,我们在列表中有6个条目。但请记住,每个项目的索引都是从 0 开始的!如果我们试图查看位置索引 6 的列表项目,我们会收到错误...记住最后一个数字的索引(21 ) 5 。所以这一行:

The list also has a concept of "length" - or the number of entries in the list. In this case we have 6 entries in the list. But remember, the index of each item started at 0! If we tried to look at the list's item at position index 6 we would get an error ... remember the index of the last number (21) is 5. So this line:

FOR index FROM 0 TO LENGTH (list) - 1 DO

表示从头开始一步一步地逐步执行列表项目( 0 )直到最后(长度 - 1

means "step through the list items one-by-one starting at the beginning (0) right through to the end (length - 1)

if item = list[index] THEN

此行正在检查用户通过键盘输入的是否与(=)位于位置的数字相同在列表中。所以第一次通过它将检查 item = list [0] 然后下一个循环将检查 item = list [1] 如果数字匹配,则执行跟随 END IF的行动

This line is checking to see if the item that the user entered via the keyboard is the same as (=) the number that is at position index in the list. So the first time through it will check item = list[0] then the next loop will check item = list[1]If the numbers do match then perform the actions that follow up to the END IFI.e.

SET found TO True
SEND 'Found' TO DISPLAY

第一行是将flag或signal设置为True,这意味着是的,我们找到了匹配。然后你通过显示找到这个词让用户知道它已被找到。



这有帮助吗?



正如OriginalGriff指出的那样,不是学习的方式。我希望这个详细的解释足以让你现在继续自己。如果你继续发布这样的问题,我担心你会感到吝啬。我们不是一个教程网站。

The first line is setting that "flag" or "signal" to True, which means "yes, we have found a match". You then let the user know it's been found by displaying the word 'Found'.

Does that help?

As OriginalGriff has pointed out this is not the way to learn. I'm hoping that this detailed explanation is going to be sufficient to let you carry on on your own now. I'm afraid you will get short shrift if you keep posting questions like this. We are not a tutorial site.


我们解释你找到的每一段代码请你解释这个伪代码给我? [ ^ ]并不是一个帮助你学习的东西。



阅读伪代码,阅读它应该执行的任务,并从中解决它正在做的事情 - 这是非常明显的事情,如果你完全按照你的课程你应该明白这一点 - 特别是如果你说这些不是你的作业,而是你的修订指南。

如果您已经在修改,那么在理解课程开始时可能已经涵盖的内容有点晚了...
Us explaining each and every piece of code you find Can you please explain this pseudo-code to me?[^] isn't goign to help you learn.

Read the pseudo code, read the task it is supposed to perform, and work out what it is doing from that - this is pretty obvious stuff, if you have followed your course at all you should understand this - especially if as you say these are not your homework but your revision guides.
If you are already revising, it's a bit late to not understand the stuff which was probably covered at the start of your course...


请阅读< a href =https://www.codeproject.com/KB/FAQs/QuickAnswersFAQ.aspx>代码项目快速解答常见问题解答 [ ^ ]。如果您真的不了解基础知识,那么您应该掌握一本书,或者尝试一些在线教程。对于Python,您可以从 Python教程 - Python 3.4.8文档开始[ ^ ]。
Please read Code Project Quick Answers FAQ[^]. If you really do not understand the basics then you should get hold of a book, or try some online tutorials. For Python you can start at The Python Tutorial — Python 3.4.8 documentation[^].


这篇关于能告诉我这个伪代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆