Tuesday, April 21, 2009

Assignment 01A - Pseudo-Code

In the first part of the first assignment, you should write a small, but detailed, pseudo-code, just as the tea example I gave you last class.

First write the human instructions, then "translate it" to a format a computer could possibly understand. You should pick something simple and ordinary, such as "boiling an egg", or "walking around the block".

Here is, again, the "making tea" example. For humans, we would simply write:
boil the water
put it in a cup
put a teabag in the water
add sugar if you want

But for a computer, these simple four statements would need much more thorough instructions:
function boilWater:
with waterBoiler
fill with coldWater
if waterBoiler = full:
stop fill
turn waterBoiler.switch to „on“
when waterBoiler.switch = „off“:
execute function fillCup

function fillCup:
get cup
place cup right to waterBoiler
with waterBoiler:
move 20cm up
turn -90°
if cup = „full“
with waterBoiler:
turn 90°
move 20cm down
execute function makeTea

function makeTea:
desiredSugar = 2
desiredTime = 3min

get teaBag
with teaBag:
place inside cup

start counting time
if time = 3min:
put teaBag in initial position

if desiredSugar > 0:
execute function putSugar
else:
finish

And it would go on and on. We would also need to specify what those objects are (waterBoiler, teaBag...).

When you are writing your pseudo-code, keep in mind the following overall rules:
  • Be aware if indenting: Python relies heavily on indenting to structure and process the code. It also helps make the code more organized, by nesting actions.
  • Think about all data you need to pass the computer and, most important, how and when it should use this data
You should post here your pseudo codes in the blog, along this week until Saturday, 25.04, so we can have it for next class.

In order to post your pseudo-code formatted as above, you can follow this tip.

No comments:

Post a Comment