33 lines
876 B
Python
33 lines
876 B
Python
class Fraction:
|
|
def __init__(self, numerateur, denominateur):
|
|
if denominateur == 0:
|
|
raise ValueError("Le denominateur ne peut etre nul")
|
|
if not isinstance(denominateur, int) or not isinstance(numerateur, int):
|
|
raise TypeError("Le numerateur/denominateur doit etre un entier")
|
|
self.numerateur = numerateur
|
|
self.denominateur = denominateur
|
|
|
|
@property
|
|
def quotient(self):
|
|
return self.numerateur / self.denominateur
|
|
|
|
print("Debut programme")
|
|
try:
|
|
tiers = Fraction(1, '0')
|
|
print(tiers.quotient)
|
|
except (ValueError, TypeError) as msg :
|
|
print(msg)
|
|
|
|
liste = [1,2,3,4]
|
|
dico = {'nom': "John"}
|
|
|
|
try:
|
|
print(dico['prenom'])
|
|
print(liste[7])
|
|
except LookupError as msg:
|
|
if isinstance(msg, KeyError):
|
|
print("La cle n'existe pas")
|
|
else:
|
|
print(msg)
|
|
|
|
print("Fin du programme") |