无法将变量添加到数字Python

无法将变量添加到数字Python,python,python-2.7,variables,Python,Python 2.7,Variables,↑ 是的 Python 2.7.13 我想输入0作为第一个提示,然后输入.37作为下一个提示,结果是.481 出于某种原因,我知道我搞砸了,我无法添加上面定义的“second”变量,“overallheight”值不起作用: u1 = 12.5 first = .481 u2 = 2 length = u1 * 12 second = u2 / 64 overallheight = first - second #this line is not subtracting height_multi

↑ 是的

Python 2.7.13

我想输入0作为第一个提示,然后输入.37作为下一个提示,结果是.481 出于某种原因,我知道我搞砸了,我无法添加上面定义的“second”变量,“overallheight”值不起作用:

u1 = 12.5
first = .481
u2 = 2
length = u1 * 12
second = u2 / 64
overallheight = first - second #this line is not subtracting
height_multiply = overallheight / .3075
width_multiply = length / 108
def calc():
    x = float(raw_input("first prompt"))
    y = float(raw_input("second prompt"))
    y1 = (y - .0625) * height_multiply
    x1 = x * width_multiply
    y2 = y1 + second #this is the 'second' that needs to be added
    print("(%s,%s)") % (x1, y2)
while 1>0:
    calc()`

您使用的是Python 2,因此与整数一起使用的
/
将执行整数除法。
second=u2/64
with
u2=2
2/64
,它是
0


要进行浮点除法,您可以使用来自未来导入除法的
或明确使用浮点:
u2=2.0

请告诉我们您得到的错误,好吗?这不是错误,我只是打印了错误的值。如果您在询问堆栈溢出之前尝试调试它,您会知道上面的那一行(
second=u2/64
)将
second
的值设置为0,从而查找运算符
/
,并自己解决问题。非常感谢,这很有帮助。干杯!