How to control a digital turtle using Python coding?

11.15.2020

Experiment leads: Karin and Yutong

 

In our first visit to KIPP this school year, we introduced basic python coding to students from the 6th grade. Due to the pandemic, SFA visits are now virtual and we invited students and teachers from KIPP to join us via Zoom. After a short self-introduction and presentation on python coding, students were separated into 9 breakout rooms, where they worked with SFA mentors on how to control the movement of a digital turtle using python coding.  

 

Students each had their own programming environment on a Google Colaboratory notebook. They first installed the Turtle module (do this on your own using this link!) on their notebook and then learned how to call functions from the module. We introduced the `initializeTurtle()` function, which creates a new digital turtle drawing; the `forward(x)` function, which moves the turtle forward on the “canvas” by a specified amount; and the `right(x)` functions, which turns the turtle a specified number of degrees to the right. 

 

To gain an intuition for how functions and parameters work, students experimented with changing function parameters and observing how that change affected their turtle’s behavior. We also showed them how to define a variable and pass the variable to the function and encouraged students to experiment with changing the variable’s name and value. This warm up exercise introduced several important programming concepts: functions, function parameters, and variables.

 

The cool thing about the digital turtle is that when it moves, it traces its path with a line, so you can draw by moving the turtle! We asked the students to figure out how to draw a square with the turtle using what they learned about the `forward` and `right` functions. How many times will the turtle need to go forward? How many times will it need to go right? Answering these questions helps introduce the students to basic computational thinking: figuring out what steps the computer needs to take in order to achieve the final results. The best part is they can write their own code and watch what happens to the turtle to find out whether they were right!

 

Finally, we showed the students some code that uses an important programming structure called a for loop to draw a square with the turtle (do this on your own using this link!). We talked about how to change the code so that it could draw shapes with any number of sides, and the students experiment themselves to draw different shapes. Some students found that if they drew a shape with a very large number of sides, they would end up approximating a circle.

 

At the end of the visit, students were able to code to control the moving path of the digital turtle to draw different shapes including a hexagon and even a circle in addition to the square and triangle that they just learnt in class a few days prior to the SFA visit. This demonstration allowed us to introduce python coding and geometry to students. We also provided additional python examples that are more complicated than the demonstration we showed in the visit for students to explore python after class, which are included in the link here.

 

The Team
The Code