-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexo.py
58 lines (43 loc) · 1.17 KB
/
exo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import math
def exercice_1(a, b):
"""Fonction qui renvoie le produit de 2 nombres
>>> exercice_1(2,3)
6
>>> exercice_1(2,4)
8
"""
if(type(a)) == str or type(b) == str:
raise TypeError("Invalid argument")
else:
return a*b
def exercice_2(x, a, b):
if x < a:
if type(b) != int and type(b) != float:
raise TypeError("Invalid argument")
else:
return -255
elif x > b:
if type(a) != int and type(a) != float:
raise TypeError("Invalid argument")
else:
return 255
else:
return x
class Exercice_3:
def __init__(self, r):
if type(r) != int and type(r) != float:
raise TypeError("Radius must be integers or float")
elif r < 0:
raise ValueError("Radius must be strictly positive")
else:
self.r = r
def aire(self):
return math.pi*self.r * self.r
def perimetre(self):
return 2 * math.pi * self.r
def dans_cercle(self, x, y):
norme = math.sqrt(x*x + y*y)
if norme <= self.r:
return True
else:
return False