Exercise 2 - Primer on Loop Referring to the code for drawing an equilateral triangle provided to you earlier in this prac sheet, you may have noticed that, in order to draw the triangle, we are...


Exercise 2 - Primer on Loop<br>Referring to the code for drawing an equilateral triangle provided to you earlier in this prac<br>sheet, you may have noticed that, in order to draw the triangle, we are repeating a set of two<br>commands three times i.e. robot.forward( 100) followed by robotright(120). Python (and many other<br>programming languages) provide us a tool called a

Extracted text: Exercise 2 - Primer on Loop Referring to the code for drawing an equilateral triangle provided to you earlier in this prac sheet, you may have noticed that, in order to draw the triangle, we are repeating a set of two commands three times i.e. robot.forward( 100) followed by robotright(120). Python (and many other programming languages) provide us a tool called a "Loop" to repeat a certain set of steps a certain number of times. As usual, in order to use loops, we have learn the correct Python syntax for it. The following Python code uses a loop to draw the same equilateral triangle as the code provided earlier: import turtle wn - turtle.Screen() wn.bgcolor("white" robot - turtle. Turtle() robot. setheading(90) robot shape("turtle") robot.colort"green" robot. pensize(3) for i in range(3): robot. forward( 100) robot. right(120) wn.exitonclick() Note that the lines that fall under the line that starts with "for" have to be indented; this means that you have to insert spaces or tabs (USE TABS!), and the number of spaces or tabs for all lines under the loop need to be the same. My advice: use only a single tab for each of these lines. Ok, now that we have this, try to use the above example to draw the following shape (noting that the lengths of the sides can all be equal, say, 50 units). This should be done in the Exercise2 file provided in your Replit prac. Exercise 3- Valentine's Special [ Show some love (but don't get carried away) by writing a program (in Exercise3 in Replit) to get the robot to draw the well known shapes below: two intertwining hearts (..soaring away into the sunset...). Make sure the hearts are PINK IN COLOUR. Note that it is perfectly fine for your program to have lines within the hearts. What is important is the outline. So if your shapes end up looking like the below, it will be fine too.
Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here