想要用python及turtle绘制中国国旗
并实现能让用户自主输入国旗的长,宽
但是家里电脑在导入turtle时总是报错
故恳请各位帮在下对以下代码进行调试并指出错误,谢谢!
具体代码如下:
print("Please type in the length.")
length = int(input(">")) #输入长
print("Please type in the width.")
width = int(input(">")) #输入宽
import turtle
turtle.shape()
turtle.screemsize(length,width)
turtle.bgcolor("red")
turtle.color("yellow","yellow")
k = width / 20 #单位长度
a = k * 6 #大星星边长
b = k * 1.8 #小星星边长
turtle.penup()
turtle.goto(- 13 * k,6 * k)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.foward(a)
turtle.left(144)
turtle.end_fill()
#大星星
turtle.penup()
turtle.goto(- 6 * k,0.5 * k)
turtle.pendown()
turtle.left(30)
turtle.begin_fill()
for i in range(5):
turtle.foward(a)
turtle.left(144)
turtle.end_fill()
turtle.penup()
turtle.goto(- 6 * k,7.5 * k)
turtle.pendown()
turtle.left(-40)
turtle.begin_fill()
for i in range(5):
turtle.foward(a)
turtle.left(144)
turtle.end_fill()
turtle.penup()
turtle.goto(- 4 * k,5.9 * k)
turtle.pendown()
turtle.left(7)
turtle.begin_fill()
for i in range(5):
turtle.foward(a)
turtle.left(144)
turtle.end_fill()
turtle.penup()
turtle.goto(- 4 * k,3.2 * k)
turtle.pendown()
turtle.left(-15)
turtle.begin_fill()
for i in range(5):
turtle.foward(a)
turtle.left(144)
turtle.end_fill()
turtle.hideturtle()
#隐藏画笔
input()
看截图像是在开发工具上截图,导入报错一般情况是自己的导入所引用的包没有安装;另一个情况是自己的电脑安装了这个包但是开发工具配置的编译器并不是电脑上的python运行环境,导致已安装的包并不能被检索到。