Δημοσιεύτηκε: 27 Ιαν 2013, 19:16
από Charval
Παιδιά, σας ευχαριστώ πολύ για τις απαντήσεις σας, το αρχικό πρόβλημα λύθηκε. Όμως κάτι συμβαίνει και η εκτέλεση του προγράμματος διακόπτεται.

Παραθέτω καταρχάς τον κώδικα:
Κώδικας: Επιλογή όλων
#!/usr/bin/python3

# -*- coding: utf8 -*-

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

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

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

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

c = 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!")


ο οποίος κατά την εκτέλεση στο terminal εντοπίζει error κάπου στη διακρίνουσα D και δεν καταλαβαίνω γιατί. :thumbdown:

Εικόνα