jeudi 1 octobre 2015

How to make a turtle in python change colors randomly

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)

This is my code. I would like to know how to make the turtle change colors randomly through out the whole program. It should be changing color every .5 seconds through out the whole program. How should I do this. I tried to import random. This is for a school assignment. Please Help.




Aucun commentaire:

Enregistrer un commentaire