Skip to content

Instantly share code, notes, and snippets.

@Ad115
Last active September 19, 2018 19:28
Show Gist options
  • Save Ad115/e9189175da28205223ee8be46ae5d67d to your computer and use it in GitHub Desktop.
Save Ad115/e9189175da28205223ee8be46ae5d67d to your computer and use it in GitHub Desktop.
Un caso común de uso de el operador módulo en Python
import turtle
squirtle = turtle.Turtle()
# Los colores que usaremos
colors = ["red", "yellow", "blue", "orange", "green", "purple"]
n_colors = len(colors)
for i in range(100):
# Obtén el índice del color
idx = i % n_colors
# Obtén el color
color = colors[idx]
# Cambia el color
squirtle.pencolor(color)
# Avanza
squirtle.forward(i)
squirtle.left(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment