How would you write pseudocode for drawing an 8-by-8 checkerboard of squares, where none of the squares have to be full? (Can all be empty)
I don't quite get the pseudocode concept.
How would you write pseudocode for drawing an 8-by-8 checkerboard of squares, where none of the squares have to be full? (Can all be empty)
I don't quite get the pseudocode concept.
Pseudo code is writing out the code in form that is like code but not quite code. So for opening a file and printing printing out its lines of text
if file exists(path_to_file) then :
open (path_to_file)
for each line in file : print the line of the file
All you should do is create the sequence of steps needed for your problem and write it out like that. Since you mention python, just use use a more python like syntax in your pseudo code.
I suspect that you problem will be to encourage you to consider how to make functions and classes, and writing the pseudo code first will help you do this.
I'm guessing this is a class assignment, right?
In short, pseudocode is very similar to an outline. It's the structure of how you're going to go about solving the problem, without the specific details.
In this case, you'd probably use a couple for-loops, and sketch out the drawing and there...
for x in range(0,10):
for y in range(0,10):
#print out the square (x,y)
Just write something that looks like a hybrid between code and normal human explanation.
for i from 1 to 8
for j from 1 to 8
print "[ ]"
print "\n"
I would be even more generic eg.
Loop with x from 1 to 8
Loop with y from 1 to 8
draw square at x, y
Wikipedia articles use Pseudocode a lot, quite successfully. There is no standard for Pseudocode on wikipedia, and syntax varies, but here is some general information with examples: Algorithms on Wikipedia
Here are two good examples of articles with Pseudocode (more):
Using Wikipedia-like style, I'd do:
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
(Marking end of if or end of for with 'end if' or 'repeat'/'end for' is a matter of style I guess).