English subtitles

← Making a Circle out of Squares - Programming Foundations with Python

Get Embed Code
6 Languages

Showing Revision 4 created 05/25/2016 by Udacity Robot.

  1. So, one way of doing this is to draw a square
  2. and then turn a little bit to the right and then
  3. draw another square. And then turn a little bit to the
  4. right again and then draw another square. And keep doing that. Let's
  5. build that. So, here's the piece of code that draws a
  6. square. And after I've done that, what I want the turtle to
  7. do is turn a little bit to the right. So, let
  8. me add a piece of code that says brad.right, let's say by
  9. ten degrees. Now, because I want these two statements to
  10. happen over and over again, I will put them inside a loop. So let me do that. So
  11. I'm going to add a for loop by saying for i in range, let's say this
  12. loop runs four times. I'll add a colon and then put these two
  13. things inside the loop. Let me save, and run, and see
  14. what happens. Ah-ha, so here is the output. We've drawn two squares,
  15. three squares and it should stop, there it is four squares. So all I have to
  16. do now, is let the turtle keep going around the circle, which has 360 degrees.
  17. So, this loop should run not four times, but 36
  18. times instead. Let me save and
  19. run that. All right. There it is, folks. A circle made out of squares. Now
  20. I'm going to put some background music behind this
  21. video and let you enjoy our final creation.
  22. [MUSIC]
  23. [MUSIC]