first commit

This commit is contained in:
Debucquoy 2022-09-29 17:42:52 +02:00
commit 9386728e96
No known key found for this signature in database
GPG Key ID: 3B9EEB701C9E2919
8 changed files with 272 additions and 0 deletions

38
22sept/main.py Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env python
from math import pi
def volume_sphere(rayon):
return (4/3)*pi*rayon**3
def prix_livre(nbr, prix):
return ((prix*nbr) - (prix*nbr*(40/100)) + (3 + 0.75*(prix - 1)))
def time_per_miles(km, h, m, s):
mi = km / 1.61 # km to mi
total_sec = h *60 + m * 60 + s
return mi / total_sec
def time_per_miles(km, h, m, s):
mi = km / 1.61 # km to mi
total_sec = h *60 + m * 60 + s
return mi / total_sec
def mi_per_h(km, h, m, s):
mi = km / 1.61
total_h = h + m / 60 + s /3600
return mi / total_h
if __name__ == "__main__":
vol = volume_sphere(5)
print(vol)
nbre_livre = prix_livre(60, 24.95)
print(nbre_livre)
time = time_per_miles(10, 0, 43, 30)
print(time)
speed = mi_per_h(10, 0, 43, 30)
print(speed)

BIN
22sept/serie1.pdf Normal file

Binary file not shown.

32
29sept/ex1-2.py Normal file
View File

@ -0,0 +1,32 @@
def rendreMonnaie(prix, monnaie):
x1, x2, x3, x4, x5 = monnaie # Chaques billets en entree (20, 10, 5, 2, 1)
given = (x1*20) + (x2*10) + (x3*5) + (x4*2) + (x5*1)
rest = given - prix
if rest < 0:
return f"vous n'avez pas assez d'argent. Il manque : {-rest}"
o1 = rest // 20
rest = rest % 20
o2 = rest // 10
rest = rest % 10
o3 = rest // 5
rest = rest % 5
o4 = rest // 2
rest = rest % 2
o5 = rest // 1
rest = rest % 1
return o1, o2, o3, o4, o5
if __name__ == "__main__":
prix = int(input("quel est le prix :"))
print("entrez maintenant les billets")
mon = (int(input("20e:")),int(input("10e:")),int(input("5e:")),int(input("2e:")),int(input("1e:")))
print(rendreMonnaie(prix, mon))

Binary file not shown.

90
29sept/ex2-1/droite.py Normal file
View File

@ -0,0 +1,90 @@
def droite(p1: tuple,p2: tuple) -> tuple:
"""retourne un 3-uple d'une droite selon ax+by=c
:p1: tuple du point 1
:p2: tuple du point 2
:returns: 3-uple (a,b,c) tq ax+by=c
"""
x1, y1 = p1
x2, y2 = p2
if p1 == p2:
return
if x2-x1 == 0:
return 1, 0, 0
a = -(y2-y1)/(x2-x1)
c = a*x1
b = (-a*x2 + c) / y2
return a, b, c
def appartient(d, p):
"""
:d: equation d'une droite
:p: point
:returns: true si point est dans droite
"""
a, b, c = d
x, y = p
return a*x + b*y == c
def paralleles(d1, d2):
"""
:d1: droite 1
:d2: droite 2
:returns: true si d1 et d2 sont paralleles sinon false
"""
a1, b1, c1 = d1
a2, b2, c2 = d2
return a1/b1 == a2/b2
def intersection(d1, d2):
"""Trouve le point d'intersection
:d1: droite 1
:d2: droite 2
:returns: retourne le point d'intersection sinon None
"""
a1, b1, c1 = d1
a2, b2, c2 = d2
if paralleles(d1, d2):
return # paralleles donc pas d'intersection
y = (c2*a1 - a2*c1) / (-a2*b1 + b2*a1)
x = (c1 - b1*y)/ a1
return x, y
def droite_normale(d, p):
"""TODO: trouve la normale dune droite passant par un point.
:d: droite
:p: point
:returns: retourne la normale de la droite passant par le point
"""
def symetrie_orthogonale(d, p):
"""TODO: Docstring for symetrie_orthogonale(d, p.
:returns: TODO
"""
pass
def distance_droite_point(d, p):
"""TODO: Docstring for distance_droite_point.
:returns: TODO
"""
pass

View File

@ -0,0 +1,37 @@
from droite import *
def test(function, p1, p2, exp_result):
fun_result = function(p1, p2)
if fun_result == exp_result:
print(f"{function.__name__}({p1}, {p2}) == {exp_result} --- SUCCESS!")
else:
print(f"{function.__name__}({p1}, {p2}) == {exp_result} --- ERROR! (result was:{fun_result})")
def tests():
test(droite, (-2, 0), (1, 1.5), (-0.5, 1, 1.0))
test(droite, (0, -3), (0, 5), (1, 0, 0))
test(droite, (0, -1), (0, -1), None)
test(appartient, (-0.5, 1, 1.0), (-2, 0), True)
test(appartient, (-0.5, 1, 1.0), (1, 1.5), True)
test(appartient, (-0.5, 1, 1.0), (0, -1), False)
test(paralleles, (0, 1, 1), (0, 2, 3), True)
test(paralleles, (-0.5, 1, 1.0), (0, 2, 3), False)
test(intersection, (-0.5, 1, 1.0), (0, 2, 3), (1.0, 1.5))
test(intersection, (0, 1, 1), (0, 2, 3), None)
test(droite_normale, (-0.5, 1, 1.0), (-2, 0), (2.0, 1, -4.0))
test(droite_normale, (-0.5, 1, 1.0), (3, 4), (2.0, 1, 10.0))
test(symetrie_orthogonale, (-0.5, 1, 1.0), (-2, 0), (-2.0, 0.0))
test(symetrie_orthogonale, (-0.5, 1, 1.0), (3, 4), (2.0, 1, 10.0))
test(distance_droite_point, (-0.5, 1, 1.0), (-2, 0), 0.0)
if __name__ == "__main__":
tests()

75
29sept/plot.py Normal file
View File

@ -0,0 +1,75 @@
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
class Plot(object):
"""Show graphical drawing of lines from their equation."""
def __init__(self):
self.setXAxis()
self.functs = []
self.verts = []
def prepare(self, line):
"""Add the given line to the plot.
The line is not shown until the method show is called.
Args:
line: a triplet `(a, b, c)` representing the coefficients of the
line of equation `ax + bx + c = 0`.
"""
a, b, c = line
if b == 0:
if a == 0:
raise ValueError('Not a line.')
else:
self.verts.append(line)
else:
self.functs.append(line)
def setXAxis(self, xmin=-10, xmax=10):
self.xmin = xmin
self.xmax = xmax
def reset(self):
self.setXAxis()
self.functs = []
self.verts = []
def plot(self, t, y, line):
a, b, c = line
plt.plot(t, y, label='%.4g*x + %.4g*y = %.4g' % (a, b, c))
def draw(self):
for a, b, c in self.functs:
t = np.array([self.xmin, self.xmax])
y = (-a * 1.0 / b) * t + (c * 1.0 / b)
self.plot(t, y, (a, b, c))
for a, b, c in self.verts:
x = c / a
self.plot([x, x], plt.ylim(), (a, b, c))
plt.axis('tight')
plt.legend()
plt.title('Exercices sur les droites')
plt.xlabel('x')
plt.ylabel('y')
plt.grid(True)
def save(self, filename):
self.draw()
plt.savefig(filename)
def show(self):
self.draw()
plt.show()
if __name__ == '__main__':
p = Plot()
p.prepare((1, 1, 3))
p.prepare((-2, 1, -1))
p.prepare((1, 0, -5))
p.show()
input()

BIN
29sept/serie2.pdf Normal file

Binary file not shown.