维基百科文章大量使用伪代码,而且相当成功。维基百科上的伪代码没有标准,语法也各不相同,但这里有一些带有示例的一般信息:维基百科上的算法
以下是使用伪代码的文章的两个很好的示例(更多):
使用类似维基百科的风格,我会这样做:
for i from 0 to 7
for j from 0 to 7
if (i + j) is even then
paint square (i, j) black
else
paint square (i, j) white
Run Code Online (Sandbox Code Playgroud)
(我认为用“end if”或“repeat”/“end for”标记if的结束或for的结束是一种风格问题)。
伪代码是以类似于代码但又不完全是代码的形式写出的代码。所以为了打开一个文件并打印出它的文本行
if file exists(path_to_file) then :
open (path_to_file)
for each line in file : print the line of the file
Run Code Online (Sandbox Code Playgroud)
您应该做的就是为您的问题创建所需的步骤序列并像这样写出来。既然你提到了 python,就在你的伪代码中使用更像 python 的语法。
我怀疑你的问题是鼓励你考虑如何制作函数和类,首先编写伪代码将帮助你做到这一点。
我会更加通用,例如.
Loop with x from 1 to 8
Loop with y from 1 to 8
draw square at x, y
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
49932 次 |
| 最近记录: |