【发布时间】:2016-09-08 21:00:00
【问题描述】:
这里是 CS 初学者。我试图让 python 2.7 使用一个函数绘制一个矩形,该函数只有海龟对象、左上角坐标和右下角坐标作为参数。我知道有更简单的绘制矩形的方法,但我试图只使用角坐标。
运行我当前的代码后,我得到以下信息:
TypeError: 不能将序列乘以“float”类型的非整数
我知道这可能很简单,但我无法弄清楚我做错了什么,因此我们将不胜感激。
我的代码如下:
from turtlegraphics import Turtle
def drawLine(t1,x1,y1,x2,y2):
t1.setWidth(1)
t1.setColor(0,0,0)
t1.up()
t1.move(x1,y1)
t1.down()
t1.move(x2,y2)
def rectangleSimple(t2,upperLeftPoint,lowerRightPoint):
t2.setWidth(1)
t2.setColor(0,0,0)
t2.up()
t2.move(upperLeftPoint)
t2.down()
t2.setDirection(270)
t2.move(lowerRightPoint[2])
t2.setDirection(0)
t2.move(lowerRightPoint)
t2.setDirection(90)
t2.move(upperLeftPoint[2])
t2.setDirection(180)
t2.move(upperLeftPoint)
def main():
t1 = Turtle()
x1 = 0
y1 = 0
x2 = 50
y2 = 0
drawLine(t1,x1,y1,x2,y2)
t2 = Turtle()
upperLeftPoint = (-100,50)
lowerRightPoint = (100,-50)
rectangleSimple(t2,upperLeftPoint,lowerRightPoint)
main()
【问题讨论】:
标签: python-2.7 turtle-graphics