Как разрешить десятичные числа в этой программе? [дубликат]Python

Программы на Python
Anonymous
Как разрешить десятичные числа в этой программе? [дубликат]

Сообщение Anonymous »

Код: Выделить всё

class QuadraticFormula:

def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c

def quadraticFormula(self):
try:
root1 = (-(self.b)+((self.b ** 2 - (4 * self.a * self.c)) ** 0.5)) / (2 * self.a)
root2 = (-(self.b)-((self.b ** 2 - (4 * self.a * self.c)) ** 0.5)) / (2 * self.a)
except ZeroDivisionError:
return "\nVariable A cannot be equal to 0."
else:
if (self.b ** 2 - (4 * self.a * self.c)) == 0:
return f"\n\nThe one real root of the Quadratic Graph with variables {self.a}, {self.b} and {self.c} is {root1}."
elif (self.b ** 2 - (4 * self.a * self.c)) > 0:
return f"\n\nThe two real roots of the Quadratic Graph with variables {self.a}, {self.b} and {self.c} are, {round(root1, 2)} and {round(root2, 2)}."
elif (self.b ** 2 - (4 * self.a * self.c)) < 0:
return f"\n\nThe two complex roots of the Quadratic Graph with variables {self.a}, {self.b} and {self.c} are, {(root1)} and {(root2)}."

a = int(input("Enter the variable a of the quadratic equation (ax^2 + bx + c = 0): "))
b = int(input("\nEnter the variable b of the quadratic equation (ax^2 + bx + c = 0): "))
c = int(input("\nEnter the variable c of the quadratic equation (ax^2 + bx + c = 0): "))

qf = QuadraticFormula(a, b, c)
print(qf.quadraticFormula())
Так как мне разрешить десятичные значения (например, 4,5) и запретить ввод строк?
Я хочу, чтобы это проверялось внутри квадратичной формулы () формула.

Подробнее здесь: https://stackoverflow.com/questions/788 ... is-program

Вернуться в «Python»