3つのランダムな色で円を描きたいと思います。しかし、このコードでは、円を描くために使用される、出力が色なしである:それは黄色や青色のときgetColor()
機能でPython Turtleは無作為に色付けされた円を描きます
import turtle
window=turtle.Screen()
tess= turtle. Turtle()
import random
def getColor():
color=random.randint(1,3)
if color==1:
color="red"
elif color==2:
color=="yellow"
elif color==3:
color=="blue"
return color
print (random.randint(1,3))
def drawFace (x,y):
tess.penup()
tess.goto(x+5,y+10)
tess.circle(10)
tess.goto(x+15,y+10)
tess.circle(10)
tess.pendown()
あなたは 'getColor()'を使用していません。少なくともこのコードではありません。また、2つの異なるrandint()呼び出しで2つの異なる数値を生成しています。 – Lafexlos