Kevin's functional turtle

by kevin-kao

24 May 2018

This is my original logical turtle exercise:

What I was trying to do is to refactor the original one and make it more concise and clearer. Here is what I’ve improved:

There were a couples of circles that I drew. I tried to use def: to reduce the redundant part, like this:

def draw_circle(x, y):
  kev.fill(True)
  kev.penup()
  location = kev.goto(x, y)
  kev.pendown()
  kev.circle(30)
  kev.color("chocolate")
  kev.fill(False)
  return location

Besides, I also replaced the following with def:

kev.penup()
kev.goto(0, -50)

By doing so, I reduced the repetition again.

In the end, quite a few codes were replaced by def:. This can definitely turn my coding easier to understand within a short time. I think def: is quite useful and very powerful. I can build up the new function and create what I want. This is incredible!

I am a visiting student here in UNC and an incoming student at Duke University studying quantitative management for my master degree this fall. Find kevin-kao on Twitter, Github, and on the web.