Tuesday, July 29, 2014

Solutions: Repeat Loops for Drawing Squares with Pro-Bot

Let’s write down the code for drawing a square with sides 6 cm each, using Pro-Bot. 

Assuming you start at the left most bottom corner and you are facing forward, the square can be drawn using the following code:


  

   Fd 6
   Rt
   Fd 6
   Rt
   Fd 6
   Rt
   Fd 
   Rt     // optional




Do you see a repeating pattern in the code?

Circle the part in the code that repeats. Circle the corresponding part in the picture as well.

Write down the part of the code that repeats.

   Fd 6
   Rt


How many times do we repeat the pattern?

   4 times

Can you now rewrite the code for the above square using a Repeat loop?

   Rpt  4  [                                 
   Fd 6
   Rt
   ]


How many lines of code were there in your first version, without the Repeat Loop?

    8 lines

How many lines of code are there in your new version using the Repeat Loop?

    4 lines

By how much did you reduce the number of lines of code in your new version?

    4 lines

Can you now write a program for Pro-Bot to draw a square of sides 10 cm using a Repeat Loop?

   Rpt  4  [                                 
   Fd 10
   Rt
   ]



Part of a Square

The following figure looks like a square with one side of it removed. Each side measures 6 cm. Can you write a program for Pro-Bot to draw it using a Repeat Loop? 

Assuming you start at the left most bottom corner and you are facing forward, the pattern can be drawn using the following code:



Rpt 3 [
Fd 6
Rt
]















No comments:

Post a Comment