x^2是什么意思?在python中

2024-06-16 12:51:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我相信这是很基本的,我应该理解,但我不懂!

我要做的是:

> a=int(input("Enter the value for the co-efficient of x^2. "))
> b=int(input("Enter the value for the co-efficient of x. "))
> c=int(input("Enter the value for the constant term. ")) s=b**2-4*a*c
> x1=(-b+(s**(1/2)))/2*a x2=(-b-(s**(1/2)))/2*a if a==0 and b==0:
>     print("The equation has no roots.") elif a==0:
>     print("The equation has only one root and it is", -c/b) elif s<0:
>     print("The roots are not real!") else:
>     print("The roots are", x1, "and", x2)

我得到了正确的解决方案,一切都很好,但我不知道那是干什么用的。我使用它的唯一原因是因为它在练习前的课程中被用在了另一个例子中!


Tags: andoftheforinputvalueintprint
1条回答
网友
1楼 · 发布于 2024-06-16 12:51:20

它对Python来说不是什么“意义”;它只是字符串文本中的另一个字符:

"Enter the value for the co-efficient of x^2. "

你可以写点别的:

"Enter the value for the co-efficient of x to the power 2. "

除了请求input()时显示的输出之外,没有任何东西会改变。

^是指数的常用表示法。在Python中,**用于指数,其余代码就是这样使用的。

相关问题 更多 >