Your objective in this level is to complete the code below so that a turtle draws an octagon on the canvas, like this:
Create a turtle variable
Create a variable for the side length of an octagon, and ask the user to input a length (donβt forget the conversion)
Calculate a turn angle and store this in a variable. An octagon has eight sides, meaning you will have to turn your turtle eight times. Do some basic division to figure out by how many degrees your turtle will have to turn after each side.
Make the turtle draw the octagon using the side length variable and the angle variable. Note: This part will be very repetitive, but we will learn a way to avoid retyping the same commands in a few weeks
Note12.3.2.
From this lab onward you will complete labs using the code windows built into the textbook, not in Idle. You are given some code to start with, do not edit these lines!
Subsection12.3.2Level 2
Building upon your program from level 1, your objective is to calculate the area of the octagon the turtle drew and print out the area to the console.
Note12.3.3.
Octagon area = the length of a side squared, multiplied by 2, multiplied by (one plus square root of two)
Note12.3.4.
The function to get a square root is: math.sqrt()
Copy your code from Level 1 into the active code window above.
Create a variable and assign to it the area of the octagon, using the formula in the tip above for the calculation
Print out the value to the console, using the following format:
Note12.3.5.
Make sure your formula is correct by cross referencing your answer with the answer you get using a calculator
Subsection12.3.3Level 3
Below is a program similar to the type created in level 1 and 2: first a turtle draws a square, then the area of the square is printed out in the console. Objective: Convert this code into a generalized program that uses user input to set the length of the sides of the square. Use this input value to draw the square and to calculate and report the area of the square.
Note12.3.6.
You only need to add one line of code, the rest is just editing the code that is there.