# 函数,解一元二次方程 import math def quadratic(a, b, c): x1 = (-b + math.sqrt(b**2 - 4*a*c))/(2*a) x2 = (-b - math.sqrt(b**2 - 4*a*c))/(2*a) return x1, x2 def get_result(prompt=''): while True: try: a, b, c = map(float, input('Please enter a,b,c split whit \',\'\n').split(',')) print('quadratic({0} ,{1} ,{2} ) ={3}'.format(a, b, c, quadratic(a, b, c))) continue except ValueError: print('Wrong value!') return quadratic(a, b, c) get_result()
prompt=‘’ 没啥意义是自定义输入输出的变量,可以删除
Sign in to make a reply
。