Hi~ o(* ̄▽ ̄*)ブ大家好!!!!!

我又发作品啦!

好了点明主题,今天我做了一个(沙雕的)小程序——《海龟赛跑》

上代码吧:


import turtle
import random
turtle.speed(0)
turtle.penup()
turtle.goto(-140,140)
turtle.color("red")
turtle.write(0)
turtle.right(90)
turtle.forward(10)
turtle.pendown()
turtle.forward(280)
turtle.penup()
turtle.backward(290)
turtle.left(90)
turtle.forward(20)
i = 1
while i < 30:
    turtle.color("blue")
    turtle.write(i)
    turtle.right(90)
    turtle.forward(10)
    turtle.pendown()
    turtle.forward(280)
    turtle.penup()
    turtle.backward(290)
    turtle.left(90)
    turtle.forward(20)
    i += 1
a = turtle.Turtle()
a.penup()
a.goto(-160,130)
a.shape("turtle")
a.color("blue")
a.pendown()
turtle.goto(-180,130)
turtle.write(1)
b = turtle.Turtle()
b.penup()
b.goto(-160,100)
b.shape("turtle")
b.color("light blue")
b.pendown()
turtle.goto(-180,100)
turtle.write(2)
c = turtle.Turtle()
c.penup()
c.goto(-160,70)
c.shape("turtle")
c.color("red")
c.pendown()
turtle.goto(-180,70)
turtle.write(3)
d = turtle.Turtle()
d.penup()
d.goto(-160,40)
d.shape("turtle")
d.color("green")
d.pendown()
turtle.goto(-180,40)
turtle.write(4)
e = turtle.Turtle()
e.penup()
e.goto(-160,10)
e.shape("turtle")
e.color("light green")
e.pendown()
turtle.goto(-180,10)
turtle.write(5)
j = turtle.Turtle()
j.penup()
j.goto(-160,-20)
j.shape("turtle")
j.color("purple")
j.pendown()
turtle.goto(-180,-20)
turtle.write(6)
f = turtle.Turtle()
f.penup()
f.goto(-160,-50)
f.shape("turtle")
f.color("orange")
f.pendown()
turtle.goto(-180,-50)
turtle.write(7)
g = turtle.Turtle()
g.penup()
g.goto(-160,-80)
g.shape("turtle")
g.color("gold")
g.pendown()
turtle.goto(-180,-80)
turtle.write(8)
h = turtle.Turtle()
h.penup()
h.goto(-160,-110)
h.shape("turtle")
h.color("brown")
h.pendown()
turtle.goto(-180,-110)
turtle.write(9)
i = turtle.Turtle()
i.penup()
i.goto(-160,-130)
i.shape("turtle")
i.pendown()
turtle.goto(-180,-130)
turtle.write(10)
n = 0
while n < 100:
    aw = random.randint(1, 11)
    a.forward(aw)
    bw = random.randint(1, 11)
    b.forward(bw)
    cw = random.randint(1, 11)
    c.forward(cw)
    dw = random.randint(1, 11)
    d.forward(dw)
    ew = random.randint(1, 11)
    e.forward(ew)
    fw = random.randint(1, 11)
    f.forward(fw)
    gw = random.randint(1, 11)
    g.forward(gw)
    hw = random.randint(1, 11)
    h.forward(hw)
    jw = random.randint(1, 11)
    j.forward(jw)
    iw = random.randint(1, 11)
    i.forward(iw)
    n += 1


嗯,同志们代码打完了代码,你们快运行游戏吧!!!

注:每次的赢家乌龟都不同!!!

本站作者已申明原创,禁止转载!

文章内容属作者个人观点,不代表本站立场,如有侵权立删。

   口袋儿题库-青少儿编程自测题库