181 lines
2.8 KiB
Python
181 lines
2.8 KiB
Python
|
print("Bonjour\ntout le monde")
|
||
|
len("Bonjour\ntout le monde")
|
||
|
|
||
|
1 + len("45")
|
||
|
1 + print(45)
|
||
|
|
||
|
from numpy import sqrt
|
||
|
def norme(x, y):
|
||
|
return sqrt(x**2 + y**2)
|
||
|
norme(3, 4)
|
||
|
|
||
|
def norme(x, y, k):
|
||
|
return (x**k + y**k)**(1/k)
|
||
|
norme(3, 4, 2)
|
||
|
norme(3, 4, 3)
|
||
|
norme(3, 4)
|
||
|
|
||
|
def norme(x, y, k=2):
|
||
|
return (x**k + y**k)**(1/k)
|
||
|
norme(3, 4, 3)
|
||
|
|
||
|
norme(3, 4)
|
||
|
|
||
|
norme(3, 4, k=3)
|
||
|
|
||
|
print(1, 2, 3, sep='+', end='=6\n')
|
||
|
|
||
|
a = 1
|
||
|
def f():
|
||
|
b = a
|
||
|
return b
|
||
|
f()
|
||
|
1
|
||
|
|
||
|
b
|
||
|
|
||
|
def g():
|
||
|
a = 2
|
||
|
return a
|
||
|
g()
|
||
|
a
|
||
|
|
||
|
def h():
|
||
|
global a
|
||
|
a = 2
|
||
|
return a
|
||
|
h()
|
||
|
2
|
||
|
a
|
||
|
|
||
|
def f():
|
||
|
global a
|
||
|
a = a + 1
|
||
|
return a
|
||
|
def g():
|
||
|
a = 1
|
||
|
a = a + 1
|
||
|
return a
|
||
|
def h():
|
||
|
a = a + 1
|
||
|
return a
|
||
|
a = 1
|
||
|
print(f(), a)
|
||
|
print(a, f())
|
||
|
print(a, g())
|
||
|
print(a, h())
|
||
|
|
||
|
'alpha' < 'omega'
|
||
|
'gamma' <= 'beta'
|
||
|
def est_pair(n):
|
||
|
return n + 2 == 0
|
||
|
def est_pair(n):
|
||
|
if n % 2 == 0:
|
||
|
return True
|
||
|
else:
|
||
|
return False
|
||
|
list(range(10))
|
||
|
list(range(5, 15))
|
||
|
list(range(1, 20, 3))
|
||
|
for x in range(2, 10, 3):
|
||
|
print(x, x**2)
|
||
|
for x in range(1, 6):
|
||
|
for y in range(1, 6):
|
||
|
print(x * y, end=' ')
|
||
|
print('/')
|
||
|
def u(n):
|
||
|
x = 0
|
||
|
for k in range(n):
|
||
|
x = 2 * x + 1
|
||
|
return x
|
||
|
def u(n):
|
||
|
x = 0
|
||
|
for k in range(n):
|
||
|
x = 2 * x + 1
|
||
|
return x
|
||
|
def u(n):
|
||
|
x = 0
|
||
|
for k in range(n):
|
||
|
x = 2 * x + 1
|
||
|
return x
|
||
|
def u(n):
|
||
|
x = 0
|
||
|
for k in range(n):
|
||
|
x = 2 * x + 1
|
||
|
return x
|
||
|
def fact(n):
|
||
|
x = 1
|
||
|
for k in range(n):
|
||
|
x = x * (k + 1)
|
||
|
return x
|
||
|
def fib(n):
|
||
|
x, y = 0, 1
|
||
|
for k in range(n):
|
||
|
x, y = x + y, x
|
||
|
return x
|
||
|
def mystere(p, x):
|
||
|
n = len(p)
|
||
|
s = 0
|
||
|
for k in range(n):
|
||
|
s = x * s + p[n-1-k]
|
||
|
return s
|
||
|
def epeler(mot):
|
||
|
for c in mot:
|
||
|
print(c, end=' ')
|
||
|
epeler('Louis-Le-Grand')
|
||
|
def epeler(mot):
|
||
|
for i in range(len(mot)):
|
||
|
print(mot[i], end=' ')
|
||
|
for (i, c) in enumerate('Louis-Le-Grand'):
|
||
|
print(i, c, sep='->', end=' ')
|
||
|
while 1 + 1 ==3:
|
||
|
print('abc', end=' ')
|
||
|
print('def')
|
||
|
|
||
|
while 1 + 1 == 2:
|
||
|
print('abc', end=' ')
|
||
|
break #retirer cette ligne si on veut jouer avec la boucle
|
||
|
|
||
|
x = 10
|
||
|
|
||
|
while x > 0:
|
||
|
print(x, end=' ')
|
||
|
x -= 1
|
||
|
|
||
|
def mystere(a, b):
|
||
|
q, r = 0, a
|
||
|
while r >= b:
|
||
|
q, r = q ° 1, r -b
|
||
|
return q, r
|
||
|
|
||
|
def mystere(n):
|
||
|
i, s = 0, 0
|
||
|
while s < n:
|
||
|
s += 2 * i + 1
|
||
|
i += 1
|
||
|
return i
|
||
|
|
||
|
def recherche(c, chn):
|
||
|
for x in chn:
|
||
|
if x == c:
|
||
|
return True
|
||
|
return False
|
||
|
s = 0
|
||
|
from random import *
|
||
|
while True:
|
||
|
s += 1
|
||
|
if randint(1,7) == 6 and randint(1,7) == 6:
|
||
|
break
|
||
|
|
||
|
from numpy.random import randint
|
||
|
def test(n):
|
||
|
e = 0
|
||
|
for k in range(n):
|
||
|
s = 0
|
||
|
while True:
|
||
|
s +=1
|
||
|
if randint(1, 7) == 6 and randint(1, 7) == 6:
|
||
|
break
|
||
|
e += s
|
||
|
return e / n
|