understand what algorithms are; how they are implemented as programs on digital devices; and that programs execute by following precise and unambiguous instructions.
create and debug simple programs
LO: To complete tasks using comments (1)
The next two lessons will focus on writing instructions from the flow chart and code comments.
First lets look at code comments and what they are. You have already seen comments in the code examples - where the line begins with a #.
Python comments begin with a # and extend to the end of the line. A comment can appear at the start of the line or following code on a line.
#this is a comment #this is also a comment move() #this is a comment #so is this
The main reason for using comments is to make your code easier to understand - easier to be read by a human.
At this point we don't have to worry too much about comments; it will be enough to introduce them as a way of recording who did what when.
#Year group or class #name #date #Reeborg World or Name of the program
Here you can see that we have just introduced comments at the beginning of our code so you will be able to identify who has written the code. You are able to save the content of the editor window by going to Additional options/Program in editor/Save program to file. Python programs are written in plain text files ending in .py once you have saved these to your computer you can open them in a text editor like Notepad to view and print them for your records.
Anyway, back to the flow chart we made last time.
The code for this flow chart would now look like this:
#Year group or class #name #date #Tokens 1 move() take() move() put() move()