import math def solve2(a,b,d): """Solve the equation in square case""" x1=(-b+math.sqrt(d))/2/a x2=(-b-math.sqrt(d))/2/a print("\n方程式有兩個解:\nx=", x1,"or", x2) def solve1(b,c): """Solve the equation in linear case""" x=-c/b print("\n直線方程式的解:\nx=", x,) def solve3(a,b): """重根""" xs=-b/2/a print("\n方程式的解為重根:\nx=", xs,) def main(): print( """ Please give me the parameter of the square equation: ax^2+bx+c=0 """ ) a=int(input("\na=?: ")) b=int(input("\nb=?: ")) c=int(input("\nc=?: ")) d=b**2-4*a*c if a==0: print("\nYour equation is: \n", b,"x +", c,"= 0") solve1(b,c) else: print("\nYour equation is: \n",a,"x^2 +",b,"x +",c,"= 0") if d>0: solve2(a,b,d) elif d==0: solve3(a, b) else: print("\n",a,"x^2+",b,"x+",c,"=0無實數解!!") re=None while re!="n": main() re=input("\n是否要繼續?(y or n) ") while re not in ("y", "n"): re=input("\n是否要繼續?(y or n) ").lower() input("\n\nPress the enter key to quit.")