# 12.2. Week 2 Lab¶

Material Covered

Basic interactivity, turtles, operands, basic functions (Chapters 1 & 2)

## 12.2.1. Level 1¶

Your objective in this level is to complete the code below so that a turtle draws an octagon on the canvas, like this:

Tip

You are given some code to start with, do not edit these lines!

1. Create a turtle variable

2. Create a variable for the side length of an octagon, and ask the user to input a length (don’t forget the conversion)

3. 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.

4. 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

## 12.2.2. Level 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.

Tip

Octagon area = the length of a side squared, multiplied by 2, multiplied by (one plus square root of two)

Tip

The function to get a square root is: math.sqrt()

1. Copy your code from Level 1 into the active code window above.

2. Create a variable and assign to it the area of the octagon, using the formula in the tip above for the calculation

3. Print out the value to the console, using the following format: