用Python编个海龟赛跑小程序

源代码:

#!/bin/python3 from turtle import * from random import randintspeed(100)penup() goto(-140,140) for step in range(15): write(step,align="center") right(90) forward(10) pendown() trigger = -1 for step2 in range(15): trigger = trigger * -1 if trigger == 1: pendown() else: penup() forward(10) penup() backward(160) left(90) forward(20)#ada the red turtle ada = Turtle() ada.color('red') ada.shape('turtle')ada.penup() ada.goto(-160, 100) ada.pendown()# bob the blue turtle bob = Turtle() bob.color('blue') bob.shape('turtle')bob.penup() bob.goto(-160, 70) bob.pendown()# carl the yellow turtle carl = Turtle() carl.color('yellow') carl.shape('turtle')carl.penup() carl.goto(-160, 40) carl.pendown()# david the green turtle david = Turtle() david.color('green') david.shape('turtle')david.penup() david.goto(-160, 10) david.pendown()for turn in range(10): ada.right(36) bob.right(36) carl.right(36) david.right(36)for turn in range(100): ada.forward(randint(1,5)) bob.forward(randint(1,5)) carl.forward(randint(1,5)) david.forward(randint(1,5))

【用Python编个海龟赛跑小程序】效果图:

用Python编个海龟赛跑小程序
文章图片

    推荐阅读