SuperMonkey

Python ARE

Feb 13th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. # -*- coding : utf-8 -*-
  2.  
  3. ## EXERCICE 2.1
  4.  
  5. # Question 4
  6.  
  7. import time
  8.  
  9. def racine(a, n, x0):
  10.     if n == 0 :
  11.         return a
  12.     r= racine(a,n-1,x0)
  13.     return 0.5*(r+a/r)
  14.  
  15. # Question 2
  16.  
  17. def p(x):
  18.     return 4*x**3 - 2*x*x + x + log(2)
  19.    
  20. # Question 3
  21.    
  22. def N(x,mu,et):
  23.     return (1/(et*racine(2*pi))*exp(-(x-mu)**2/(2*et**2)))
  24.    
  25. # suite de fibonacci
  26.    
  27. def fibnaif(n):
  28.     if n == 0:
  29.         return 0
  30.     if n == 1:
  31.         return 1
  32.     return fib(n-1)+fib(n-2)
  33.    
  34. def fib2(n):
  35.     if n == 0:
  36.         return 0
  37.     elif n == 1:
  38.         return 1
  39.     else :
  40.         if n == 2:
  41.             return 1,0
  42.         else:
  43.             a = fib2(n-1)
  44.             return a[0]+a[1],a[0]
  45. def fib(n):
  46.     t = time.time()
  47.     a = fib2(n)
  48.     print((time.time() - t)*1000, " ms écoulées")
  49.     return a[0]+a[1]
  50.        
  51.  
  52. # feuille 1 exo 2.4
  53. # question 4
  54.  
  55. def croissantes(t,i):
  56.     if i==0:
  57.         return True
  58.     if t[i] < t[i-1] :
  59.         return False
  60.     return croissantes(t,i-1)
  61.    
  62. # paquet d'exo de la feuille
  63. def a2p(a):
  64.     if a < -3000:
  65.         return "Préhistoire"
  66.     if a < 476:
  67.         return "Antiquité"
  68.     if a < 1492:
  69.         return "Moyen age"
  70.     if a < 1643:
  71.         return "Renaissance"
  72.     if a < 1789:
  73.         return "Monarchie absolue"
  74.     if a < 1815:
  75.         return "Revolution"
  76.     if a < 2015:
  77.         return "Temps modernes"
  78.     return "vers le futur..."
  79.    
  80. def ligne(n):
  81.     for i in range(n):
  82.         print("*", end="")
  83.        
  84. def rectangle(l,L):
  85.     for i in range(l):
  86.         ligne(L)
  87.         print("\n")
  88.  
  89. def triangle(l):
  90.     for i in range(1,l+1):
  91.         ligne(i)
  92.         print("\n")
  93.        
  94. def somme_cumul():
  95.     somme = 0
  96.     for i in range(0,10):
  97.         somme = somme + i
  98.         print(somme)
  99.        
  100. def pom(max):
  101.     n = rand_int(0,max)
  102.     min = 0
  103.    
  104.     while t != 50:
  105.         pm= input()
  106.         if pm == '+' :
  107.             min = min + max/2
  108.         else :
  109.             max = (max - min)/2
  110.         t = (max + min) / 2
Advertisement
Add Comment
Please, Sign In to add comment