乌龟没有用功能绘制任何东西
因此,要进行评估,我需要发挥作用。我想做一些很酷的事情,所以我做了一个使正方形成为随机颜色的事情,并且在一个随机的位置,但是由于某种原因,它甚至不会显示乌龟。这是代码。
import turtle
import random
turt = turtle.Turtle()
turt.speed(100)
def randspotcolor():
turt.penup()
turt.goto(
random.randint(-300,300),
random.randint(-300,300)
)
turt.pendown()
turt.color(
random.randint(0,225),
random.randint(0,225),
random.randint(0,225)
)
def square():
for i in range(4):
turt.forward(100)
turt.right(90)
def dothething():
for i in range(4):
randspotcolor()
square
so for an assingment, I needed to make a function. I wanted to do something cool, so I made a thing that makes squares be a random color, and in a random spot, but for some reason, it wont even show a turtle. Here's the code.
import turtle
import random
turt = turtle.Turtle()
turt.speed(100)
def randspotcolor():
turt.penup()
turt.goto(
random.randint(-300,300),
random.randint(-300,300)
)
turt.pendown()
turt.color(
random.randint(0,225),
random.randint(0,225),
random.randint(0,225)
)
def square():
for i in range(4):
turt.forward(100)
turt.right(90)
def dothething():
for i in range(4):
randspotcolor()
square
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是您的问题:
您需要调用功能。
这是您需要添加到底部的代码:
This is your problem:
You need to call function dothething.
Here's the code you need to add to the bottom:
您的代码有两个问题:
@carictheelf说dothething()函数未在程序中使用。
您的乌龟()以浮动数颜色模式工作。
因此
此代码会引发错误。
检查colormode()函数的文档,然后将colormode更改为RGB模式。
colormode()
Your code has two problems:
As @Carictheelf said the dothething() function was not used in the program.
Your turtle() works in floating number color mode.
therefore
This code throws an error.
Check the documentation of the colormode() function, and change the Colormode to RGB mode.
colormode()