因为我已经完成了平均值和距离的编码:
x1=eval(input("Please insert a first number: "))
y1=eval(input("Please insert a second number: "))
x2=eval(input("Please insert a third number: "))
y2=eval(input("Please insert a fourth number: "))
add = x1
add = add + y1
add = add + x2
add = add + y2
average = add/4
d= distanceFormula(x1,y1,x2,y2)
print("Average:", average)
print("Distance:", d)
我现在正在添加图形,将条形图上的intergermath与python turtle图形连接起来。然而,我在键入此代码(输入)时遇到了一些问题:
def doBar(height, clr):
begin_fill()
color(clr)
setheading(90)
forward(height)
right(90)
forward(40)
right(90)
end_fill()
y_values = [str(y1), str(y2)]
x_values = [str(x1), str(x2)]
colors= ["red", "green", "blue", "yellow"]
up()
goto(-300, -200)
down()
idx = 0
for value in y_values:
doBar(value, colors[idx])
idx += 1
以下是输出结果,在正常运行后,我得到了一些错误:
Traceback (most recent call last):
in main
doBar(value, colors[idx])
in doBar
forward(height)
line 1637, in forward
self._go(distance)
line 1604, in _go
ende = self._position + self._orient * distance
line 257, in __mul__
return Vec2D(self[0]*other, self[1]*other)
TypeError: can't multiply sequence by non-int of type 'float'
那么,我如何使这段代码在图形上工作呢?