解一元二次方程(Python语言)
别妄想泡我
848次浏览
2020年07月29日 00:32
最佳经验
本文由作者推荐
树拼音-先公后私
>>> import math
>>> def main():
print("This program finds the solutions to a quadratic.
")
try:
a,b,c=eval(input("Please enter the coefficients (a,b,c):"))
discRoot=(b*b-4*a*c)
root1=(-b+disRoot)/(2*a)
root2(-b-discRoot)/(2*a)
print("
Rhe solutions are:",root1,root2)
except ValueError as excObj:
if str(excObj)=="math domain error":
print("No Real Roots.")
else:
print("You didn't give me the right numbers.")
except NameError:
print("
You didn't enter three numbers.")
except TypeError:
print("
Your inputs were not all numbers.")
except SyntaxError:
print("
Your input was not in the correct form.")
except:
print("
Something went wrong,Sorry!")
main()