社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

python中如何在负数前加括号

Rino Sula • 5 年前 • 1729 次点击  

我已经建立了一个计算二次方程并找到解决方案的项目。我已经输入了 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
 
1729 次点击  
文章 [ 4 ]  |  最新文章 5 年前