2016-10-11 1 views
0

Ich habe gerade begonnen, Python in der Schule zu lernen, hier ist mein Code für die quadratische Formellöser. Das Problem ist auf der Linie 4.Brauchen Sie Hilfe für Quadratische Formel auf Python

a=int(input('a= ')) # A-stvis mnishvnelobis micema 
b=int(input('b= ')) # B-stvis mnishvnelobis micema 
c=int(input('c= ')) # C-stvis mnishvenlobis micema 
int(a)*(x2)+int(b)*x+c=0 
d=(-b2)-4*a*c 
x1=-b+(d**(1/2)) 
x2=-b-(d**(1/2)) 
+1

Was genau * ist * das Problem, obwohl? –

Antwort

1
from math import sqrt 

a = int(input('a= ')) # A-stvis mnishvnelobis micema 
b = int(input('b= ')) # B-stvis mnishvnelobis micema 
c = int(input('c= ')) # C-stvis mnishvenlobis micema 
d = b**2 - 4*a*c 
x1 = (-b - sqrt(d))/2 
x2 = (-b + sqrt(d))/2 

print("x1 =", x1) 
print("x2 =", x2) 

Ihre Gleichung nicht benötigt wird, und Python es nicht versteht. Sie können es kommentieren, wenn Sie möchten.

versuchen und verwenden, um die Quadratwurzel (sqrt) statt Potenzierung (**)

+0

Überlegen Sie, die Antwort zu akzeptieren, wenn es so funktioniert, wie Sie es erwartet haben, danke! –