bestboli


私信TA

用户名:Tobewonderful

访问量:2011

签 名:

等  级
排  名 2687
经  验 2121
参赛次数 0
文章发表 11
年  龄 0
在职情况 学生
学  校 中南大学
专  业

  自我简介:

解题思路:

注意事项    参照用例注意保留三位有效数字

参考代码:

import math
def positive(a,b,c):
   delta=b**2-4*a*c
   s=math.sqrt(delta)
   x1=(-b+s)/(2*a)
   x1="%.3f"%x1
   x2=(-b-s)/(2*a)
   x2="%.3f"%x2
   print('x1={num1} x2={num2}'.format(num1=x1,num2=x2))

def zeros(a,b,c):
   x1=x2=(-b)/(2*a)
   x1 = "%.3f" % x1
   x2 = "%.3f" % x2
   print('x1={num1} x2={num2}'.format(num1=x1,num2=x2))

def nagative(a,b,c):
   delta = -(b ** 2 - 4 * a * c)
   s = math.sqrt(delta)
   d=(-b)/(2*a)
   d="%.3f"%d
   e=s/(2*a)
   e="%.3f"%e
   print("x1={num1}+{num2}i x2={num1}-{num2}i".format(num1=d,num2=e))

def main():
   a,b,c=map(int,input().split())
   if (b**2-4*a*c)>0:
       return positive(a,b,c)
   elif (b**2-4*a*c)==0:
       return zeros(a,b,c)
   else:
       return nagative(a,b,c)
if __name__=='__main__':
   main()

 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区