polygones.py

Created by schraf

Created on July 26, 2022

537 Bytes

Réponse à l’énigme proposée par NumWorks. La tortue trace un carré (polygone régulier à 4 côtés) avec toutes les arêtes, ce qui fait un total de 6. Appuyez sur la Flèche du haut pour passer au dessin suivant qui sera un polygone régulier à 6 côtés avec toutes les arêtes, ce qui fait un total de 15. Appuyez sur la Flèche du haut pour continuer le processus… Bon courage 😅


from turtle import *
from math import sin, cos, pi
from ion import keydown, KEY_UP
from kandinsky import draw_string

def poly(n):
  reset()
  showturtle()
  a = 2 * pi / n
  c = 0
  for i in range(n):
    for j in range(n):
      if i < j:
        c += 1
        penup()
        goto(100*cos(i*a), 100*sin(i*a))
        pendown()
        goto(100*cos(j*a), 100*sin(j*a))     
  hideturtle()
  draw_string(str(c),10,200)
  return c         

speed(0)
n = 4
while True:
  n = poly(n)
  while not(keydown(KEY_UP)):continue

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.