

## Fibonacci

def fibo(n):
    if n==0:
        return 0
    elif n==1:
        return 1
    else:
        return fibo(n-1)+fibo(n-2)

print(fibo(30))

##

import turtle as t
import math as m

t.reset()
print(t.pos())
t.goto(100,100)
t.goto(300,-100)
t.goto(400,0)
t.exitonclick()

##


def cote(longueur, angle, n):
    x,y=t.pos()
    if n==0:
        t.goto(x+longueur*m.cos(angle), y+longueur*m.sin(angle))
    else:
        cote(longueur/3,angle,n-1)
        cote(longueur/3,angle+m.pi/3,n-1)
        cote(longueur/3,angle-m.pi/3,n-1)
        cote(longueur/3,angle,n-1)


def flocon(n):
    try:
        t.reset()
    except t.Terminator:
        pass
    # t.reset()          #réinitialisation de la figure
    cote(200,m.pi/3,n)   #tracé des cotés du triangle
    cote(200,-m.pi/3,n)
    cote(200,-m.pi,n)
    t.exitonclick()

flocon(2)


##

def perm(s):
    if len(s)==1:
        return [s]
    else:
        P=[]
        Q=perm(s[1:])
        for q in Q:
            for i in range(len(s)):
                P.append(q[:i]+s[0]+q[i:])
        return P

print(perm('abc'))