Chapter 1 The way of the program
Chapter 2 Variables, expressions, and statements
Chapter 3 Hello, little turtles!
Chapter 4 Functions
Chapter 5 Conditionals
Chapter 6 Fruitful functions
Chapter 7 Iteration
Chapter 8 Strings
Chapter 9 Tuples
Chapter 10 Event handling
上面是我已经学过的内容.下面是题目.请高手帮忙.
书名是:How to Think Like a Computer Scientist: Learning with Python 3.
题目是第十章最后一题.
自学python 3.3.0,课后练习遇到难题,请各位帮忙.
-
- 帖子: 1038
- 注册时间: 2007-01-10 9:32
-
- 帖子: 1038
- 注册时间: 2007-01-10 9:32
- cuihao
- 帖子: 4793
- 注册时间: 2008-07-24 11:33
- 来自: 郑州
- 联系:
Re: 自学python 3.3.0,课后练习遇到难题,请各位帮忙.
这题和python有啥关系?自己去看看网球规则,画个图嘛,没有编程要求……
求人不如求它仨: 天蓝的Wiki 屎黄的Wiki 蓝红黄蓝绿红
Site: CUIHAO.TK Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
Site: CUIHAO.TK Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
- cuihao
- 帖子: 4793
- 注册时间: 2008-07-24 11:33
- 来自: 郑州
- 联系:
Re: 自学python 3.3.0,课后练习遇到难题,请各位帮忙.
……难道是用程序绘制?
求人不如求它仨: 天蓝的Wiki 屎黄的Wiki 蓝红黄蓝绿红
Site: CUIHAO.TK Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
Site: CUIHAO.TK Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
-
- 帖子: 1038
- 注册时间: 2007-01-10 9:32
Re: 自学python 3.3.0,课后练习遇到难题,请各位帮忙.
这是个编程题,当然要用python编写,列出所有的状态和条件.
- cuihao
- 帖子: 4793
- 注册时间: 2008-07-24 11:33
- 来自: 郑州
- 联系:
Re: 自学python 3.3.0,课后练习遇到难题,请各位帮忙.
难点在哪里?
如果只是列举状态,递归搜索不就可以了?
还是不会规则?那我也无能为力,o(╯□╰)o
如果只是列举状态,递归搜索不就可以了?
还是不会规则?那我也无能为力,o(╯□╰)o
求人不如求它仨: 天蓝的Wiki 屎黄的Wiki 蓝红黄蓝绿红
Site: CUIHAO.TK Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
Site: CUIHAO.TK Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
-
- 帖子: 1038
- 注册时间: 2007-01-10 9:32
Re: 自学python 3.3.0,课后练习遇到难题,请各位帮忙.
代码: 全选
import turtle # Tess becomes a traffic light.
turtle.setup(400,500)
wn = turtle.Screen()
wn.title("Tess becomes a traffic light!")
wn.bgcolor("lightgreen")
tess = turtle.Turtle()
def draw_housing():
""" Draw a nice housing to hold the traffic lights """
tess.pensize(3)
tess.color("black", "darkgrey")
tess.begin_fill()
tess.forward(80)
tess.left(90)
tess.forward(200)
tess.circle(40, 180)
tess.forward(200)
tess.left(90)
tess.end_fill()
draw_housing()
tess.penup()
# Position tess onto the place where the green light should be
tess.forward(40)
tess.left(90)
tess.forward(50)
# Turn tess into a big green circle
tess.shape("circle")
tess.shapesize(3)
tess.fillcolor("green")
# A traffic light is a kind of state machine with three states,
# Green, Orange, Red. We number these states 0, 1, 2
# When the machine changes state, we change tess' position and
# her fillcolor.
# This variable holds the current state of the machine
state_num = 0
def advance_state_machine():
global state_num
if state_num == 0: # Transition from state 0 to state 1
tess.forward(70)
tess.fillcolor("orange")
state_num = 1
elif state_num == 1: # Transition from state 1 to state 2
tess.forward(70)
tess.fillcolor("red")
state_num = 2
else: # Transition from state 2 to state 0
tess.back(140)
tess.fillcolor("green")
state_num = 0
# Bind the event handler to the space key.
wn.onkey(advance_state_machine, "space")
wn.listen() # Listen for events
wn.mainloop()
楼上的,能否就前面3个状态给出一点代码,我是新手.
- cuihao
- 帖子: 4793
- 注册时间: 2008-07-24 11:33
- 来自: 郑州
- 联系:
Re: 自学python 3.3.0,课后练习遇到难题,请各位帮忙.
看了看这书……怎么说呢,不是一般的编程语言入门书。
我不会他这个绘图模块,所以写不出那样的程序。
我不会他这个绘图模块,所以写不出那样的程序。
求人不如求它仨: 天蓝的Wiki 屎黄的Wiki 蓝红黄蓝绿红
Site: CUIHAO.TK Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
Site: CUIHAO.TK Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~