moving files
This commit is contained in:
		
							
								
								
									
										32
									
								
								q1/29sept/ex1-2.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								q1/29sept/ex1-2.py
									
									
									
									
									
										Normal 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)) | ||||
							
								
								
									
										124
									
								
								q1/29sept/ex2-1/droite.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								q1/29sept/ex2-1/droite.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,124 @@ | ||||
| from math import floor, sqrt | ||||
|  | ||||
|  | ||||
| def transform_mp_to_abc(m, p): | ||||
|     """transforme une équation de la forme y = mx + p to ax + by = c | ||||
|  | ||||
|     :returns: 3-uple of a, b, c | ||||
|  | ||||
|     """ | ||||
|     return -m, 1, p | ||||
|  | ||||
|  | ||||
| def transform_abc_to_mp(a, b, c): | ||||
|     """transforme une équation de la forme to ax + by = c to y = mx + p | ||||
|  | ||||
|     :returns: tuple of m, x | ||||
|  | ||||
|     """ | ||||
|     return -a/b, c | ||||
|  | ||||
|  | ||||
| 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): | ||||
|     """trouve la normale dune droite passant par un point. | ||||
|  | ||||
|     :d: droite | ||||
|     :p: point | ||||
|     :returns: retourne la normale de la droite passant par le point | ||||
|  | ||||
|     """ | ||||
|     a, b, c = d | ||||
|     x, y = p | ||||
|  | ||||
|     m, p = transform_abc_to_mp(a, b, c) | ||||
|     return transform_mp_to_abc(-1/m, y-(-1/m)*x) | ||||
|  | ||||
|  | ||||
| def symetrie_orthogonale(d, p): | ||||
|     """ retourne la symétrie orthogonale par le point p de la droite d | ||||
|     :returns: symétrie orthogonale | ||||
|  | ||||
|     """ | ||||
|     a, b, c = d | ||||
|     x, y = p | ||||
|     ap, bp, cp = droite_normale(d, p) # perpendiculaire passant par le point | ||||
|     xi, yi = intersection((a, b, c), (ap, bp, cp)) | ||||
|     return round((2*xi - x)*10)/10, round((2*yi - y)*10)/10 | ||||
|  | ||||
|  | ||||
| def distance_droite_point(d, p): | ||||
|     """ donne la distance entre une droite et un point | ||||
|     :returns: distance la plus courte entre le point et la droite | ||||
|  | ||||
|     """ | ||||
|     a, b, c = d | ||||
|     x, y = p | ||||
|     ap, bp, cp = droite_normale(d,p) # perpendiculaire passant par le point | ||||
|     xi, yi = intersection((a,b,c), (ap, bp, cp)) | ||||
|     return sqrt((xi-x)**2 + (yi-y)**2) | ||||
|  | ||||
							
								
								
									
										38
									
								
								q1/29sept/ex2-1/droite_test.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								q1/29sept/ex2-1/droite_test.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,38 @@ | ||||
| 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), (4.2, 1.6)) | ||||
|  | ||||
|     test(distance_droite_point, (-0.5, 1, 1.0), (3, 4), 1.3416407864998738) | ||||
|     test(distance_droite_point, (-0.5, 1, 1.0), (-2, 0), 0.0) | ||||
|  | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     tests() | ||||
|  | ||||
							
								
								
									
										75
									
								
								q1/29sept/plot.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								q1/29sept/plot.py
									
									
									
									
									
										Normal 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
										
									
								
								q1/29sept/serie2.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								q1/29sept/serie2.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user