Δημοσιεύτηκε: 28 Ιαν 2013, 18:37
από kamar
Ο κώδικάς σου πρέπει να γίνει κάπως έτσι:

Μορφοποιημένος Κώδικας: Επιλογή όλων
#!/usr/bin/python3

# -*- coding: utf8 -*-

print ("Welcome to 'Quadratic' solving program.")

a = int(input("Please, input the first coefficient: "))

while a == 0:
a = int(input("Be careful! That, is not a quadratic equation. Please, input a non-zero coefficient: "))

b = int(input("Now, input the second coefficient: "))

c = int(input("Now, input the constant: "))

from math import sqrt

D = b**2 + (-4)*a*c

if D > 0:
print ("The value of the determinant is: ", D, "and the two real solutions are: ", (-b+sqrt(D))/2*a, (-b-sqrt(D))/2*a)
elif D == 0:
print ("Determinant equals to zero, so we have a double real root: ", (-b)/2*a)
else:
print ("Negative determinant. Two complex solutions: ", complex ((-b)/2*a, sqrt(-D)/2*a), complex ((-b)/2*a, (-sqrt(-D)/2*a)))

print ("Thank you for using Quadratic!")