乌龟没有用功能绘制任何东西

发布于 2025-02-09 02:58:30 字数 565 浏览 1 评论 0原文

因此,要进行评估,我需要发挥作用。我想做一些很酷的事情,所以我做了一个使正方形成为随机颜色的事情,并且在一个随机的位置,但是由于某种原因,它甚至不会显示乌龟。这是代码。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱*していゐ 2025-02-16 02:58:30

这是您的问题:
您需要调用功能。

这是您需要添加到底部的代码:

dothething()

This is your problem:
You need to call function dothething.

Here's the code you need to add to the bottom:

dothething()
箜明 2025-02-16 02:58:30

您的代码有两个问题:

  1. @carictheelf说dothething()函数未在程序中使用。

  2. 您的乌龟()以浮动数颜色模式工作。
    因此

turt.color(
        int(random.randint(0, 225)),
        int(random.randint(0, 225)),
        int(random.randint(0, 225))
    )

此代码会引发错误。

检查colormode()函数的文档,然后将colormode更改为RGB模式。
colormode()

Your code has two problems:

  1. As @Carictheelf said the dothething() function was not used in the program.

  2. Your turtle() works in floating number color mode.
    therefore

turt.color(
        int(random.randint(0, 225)),
        int(random.randint(0, 225)),
        int(random.randint(0, 225))
    )

This code throws an error.

Check the documentation of the colormode() function, and change the Colormode to RGB mode.
colormode()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文