Python 2.7.6,有些字符串不会打印

时间:2015-01-05 04:45:40

标签: python string printing

“我正在Python 2.7.6中编写一个脚本来计算二次方程的根,并将它们与一些文本字符串一起打印出来。出于某种原因,字符串不会在这个脚本中打印出来,我不断得到我正在使用不正确的语法的错误消息。我很确定我正在使用正确的字符串语法,因为我可以在其他情况下让它们打印,但不是在这个特定脚本的末尾。我我想把它打印出来

“这个等式的根源是 “(第一根,无论它是什么) “以及 “(第二根,无论是什么)

“到目前为止,我还没弄清楚为什么这个脚本末尾的字符串不能打印,我完全接受任何建议。我已经尝试了很多不同的字符串和字符串方法,不幸的是到目前为止没有人工作。我对此很新,所以请不要害怕过度解释:)

# First, enter the variables a, b, and c
a=2
b=4
c=-2
# Define the variables that would appear under the radical in the written equation
b_squared=b**2
four_a_c=4 * a * c
under_the_radical=b_squared-four_a_c
radicalize=under_the_radical**.5 # Take the square root of the values under the radical
# Define the remaining variables in the equation
neg_b=-1*b
two_a=2*a
x_subone=neg_b + radicalize 
x_subtwo=neg_b - radicalize
x_one=x_subone/two_a
x_two=x_subtwo/two_a
print ‘Roots to this equation are’
print x_one
print ‘as well as’
print x_two

1 个答案:

答案 0 :(得分:2)

我怀疑行Roots to this equation areas well as没有打印。原因是您没有将字符串括在正确的引号中。使用标准ASCII引号,单引号或双引号,不是反引号,引号或其他程式化标记。以下内容适用:

print 'Roots to this equation are'
print x_one
print 'as well as'
print x_two

在语法中注意突出显示它们与"字符串"的不同颜色。在上面的代码中。