Py学习  »  Python

python中如何在负数前加括号

Rino Sula • 5 年前 • 1732 次点击  

我已经建立了一个计算二次方程并找到解决方案的项目。我已经输入了 a , b c . 当我输入这些值时,就会出现完整的二次方程。例如我输入 a:2 , b:3 , c:4 ,看起来 2x2+3x+4 . 现在的问题是负数。如果我给 价值 -3 c类 价值 -4 ,二次方程如下: 2x2+-3x+-4 . 现在我希望它以这种形式出现: 2x2+(-3)x+(-4) . 有人能帮忙吗?

这是我的代码:

a=int(input("Enter the value of a:"))
b=int(input("Enter the value of b:"))
c=int(input("Enter the value of c:"))
d = b**2-(4*a*c)
if b>0 and c>0:
    print("The quadratic equation is : " + str(a) + "x2+" + str(b) + "x+" + str(c))
elif b<0 and c<0:
    print("The quadratic equation is : " + str.format(a) + "x2+" + str(b) + "x+" + str(c))
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50900
 
1732 次点击  
文章 [ 4 ]  |  最新文章 5 年前