Answer the question
In order to leave comments, you need to log in
How to write a simple quadratic equation program in Python?
I recently started learning python from Lutz's book and the codecademy course (my first experience in programming). I tried to write a simple program for calculating quadratic equations:
a = input('Введите а:')
b = input('Введите b:')
c = input('Введите c:')
if len(a) > 0 and len(b) > 0 and len(c) > 0 and not a.isalpha() and not b.isalpha() and not c.isalpha():
d = int(b) ** 2 - 4 * int(a) * int(c)
if d > 0 or d == 0:
import math
dd = math.sqrt(d)
x = - int(b) - int(dd) / (int(a) * 2)
x1 = - int(b) + int(dd) / (int(a) * 2)
print (x, x1)
else:
print ('Рещений не имеет')
else:
print ('Введите только числа')
Answer the question
In order to leave comments, you need to log in
x = ( -int(b) - int(dd) ) / (int(a) * 2)
x1 = ( -int(b) + int(dd) ) / (int(a) * 2)
If d = 0, then it is desirable to display one root, don't you think?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question