Sign InNuggetsCoursesCodePadCheatsheet

Olympic Rings

"How can we draw the beautiful Olympic rings?" Tali and Andrew are challenging each other.

"And can we do it without tediouslyly drawing each circle by hand?"




After thinking about the problem, they come up with this solution.

Olympic Rings.
import turtle s = turtle.Screen() s.setup(600, 260) t = turtle.Turtle() t.pensize(10) colors = ["blue","orange", "black", "green", "red"] radius = 50 delta = 10 y = [0, -radius] for i in range(0, 5, 1): t.up() t.goto(i*(radius + delta), y[i%2]) t.color(colors[i]) t.down() t.circle(radius)

Did you notice some interesting concept used in this solution? Yes, it's the loop!
© CS Wonders·Home·About·Contact·Classes·Gallery·Glossary·Fun Facts