Sign InNuggetsCoursesCodePadCheatsheet

Donut Clock

The goal of this task is to design a donut-shaped, random-colored clock using the turtle, random and time modules. Here are the requirements:

  • The donut clock ticks once per second.
  • With every tick, the clock circles around once with a random color.
  • Every second the current time is displayed as text and updated.
import turtle import time import random window = turtle.Screen() window.setup(800, 380) t1 = turtle.Turtle() t1.pensize(30) t1.speed(20) t1.hideturtle() t2 = turtle.Turtle() t2.hideturtle() t2.up() t2.speed(0) t2.goto(-18, 60) for i in range(100): color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) t1.color(color) t1.circle(80) now = time.localtime() msg = str(now[3]) + ':' + str(now[4]) + ':' + str(now[5]) t2.clear() t2.write(msg) time.sleep(1)

Feel free to add your own creative twist. If you forget some of the turtle graphics functions, it's OK. Use the turtle cheatsheet as a reference.

import turtle import random import time
© CS Wonders·Home·About·Contact·Classes·Gallery·Glossary·Fun Facts