python turtle 随机颜色,如何让Python乌龟随机变色

import turtle

tina = turtle.Turtle()

tina.shape('turtle')

your_name = input("What is your name")

tina.penup()

tina.forward(20)

tina.write("Why, hello there, " + your_name + "!")

tina.backward(20)

tina.color("green")

tina.left(90)

tina.forward(100)

tina.right(90)

tina.pendown()

tina.pencolor("red")

tina.forward(50)

tina.right(50)

tina.forward(50)

tina.right(100)

tina.forward(55)

tina.left(50)

tina.forward(55)

tina.penup()

tina.forward(30)

tina.pendown()

tina.dot(10)

tina.penup()

tina.goto(100, 100)

color = input("What color is the shape")

try:

if color == ("red"):

tina.write("Your are correct" + your_name + "!")

tina.backward(20)

elif color == ("green" or "Green"):

tina.write("Sorry, It is actually Red")

tina.backward(20)

elif color == ("black" or "Black"):

tina.write("Sorry, Its is actually Red")

tina.backward(20)

elif color == ("purple" or "Purple"):

tina.write("Sorry, It is actually Red")

tina.backward(20)

elif color == ("blue" or "Blue"):

tina.write("Sorry, It is actually Red")

tina.backward(20)

except:

tina.backward(20)

tina.write("Sorry, but that isn't a color")

tina.backward(20)

这是我的密码。我想知道如何让乌龟在整个程序中随机改变颜色。它应该在整个程序中每隔0.5秒改变一次颜色。我该怎么做。我试着随机输入。这是学校作业。请帮忙。在

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值