1 Star 0 Fork 0

Wengyk/Python_learning

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
quadratic6.py 879 Bytes
一键复制 编辑 原始数据 按行查看 历史
Wengyk 提交于 2019-03-26 00:12 . add some files
# quadratic6.py
import math
def main():
print("This program finds the real solutions to a quadratic.\n")
try:
a,b,c = eval(input("Please enter the coefficients (a,b,c): "))
discRoot = math.sqrt(b*b - 4*a*c)
root1 = (-b + discRoot) / (2*a)
root2 = (-b - discRoot) / (2*a)
print("\nThe solution are: ", root1, root2)
except ValueError as exc0bj:
if str(exc0bj) == "math domain error":
print("No Real Roots.")
else:
print("You didn't give me the right number of coefficients.")
except NameError:
print("\nYou didn't enter three numbers.")
except TypeError:
print("\nYour inputs were not all numbers.")
except SyntaxError:
print("\nYour input was not in the correct form. Missing comma?")
except:
print("\nSomething went wrong, sorry!")
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wengyk/Python_learning.git
git@gitee.com:wengyk/Python_learning.git
wengyk
Python_learning
Python_learning
master

搜索帮助