Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import sqrt
- def isfloat(s):
- try:
- float(s)
- return True
- except ValueError:
- return False
- print("Bienvenue sur le résolveur de fonction au second degré")
- while 1:
- a, b, c = "", "", ""
- while not isfloat(a):
- a = input("Valeur de a : ")
- if not isfloat(a):
- print("{} n'est pas un nombre valide".format(a))
- else:
- a = float(a)
- while not isfloat(b):
- b = input("Valeur de b : ")
- if not isfloat(b):
- print("{} n'est pas un nombre valide".format(b))
- else:
- b = float(b)
- while not isfloat(c):
- c = input("Valeur de c : ")
- if not isfloat(c):
- print("{} n'est pas un nombre valide".format(c))
- else:
- c = float(c)
- D = b * b - 4 * (a * c)
- if D > 0:
- f = float((-b - sqrt(D)) / (2 * a))
- g = float((-b + sqrt(D)) / (2 * a))
- print("Deux résultats\n1 : {}\n2 : {}".format(f, g))
- elif D == 0:
- e = -b / (2 * a)
- print("Il y a un résultat : {}".format(e))
- else:
- print("Il n'y a pas de résultat")
- print('\n')
Add Comment
Please, Sign In to add comment