self.noTrace_goto(x, y)什么意思
- 教育综合
- 2023-01-11 17:43:26
python求助 和孩子一起学编程里的一段
首先, 我不懂pygame模块, 但是我觉得还是应该尝试一下
官方文档, www点pygame点org 如果你英文好的话
Screen.blit(ball.image,ball.rect)
draw one image onto another
blit(source, dest, area=None, special_flags = 0) -> Rect
Draws a source Surface onto this Surface. The draw can be positioned with the dest argument. Dest can either be pair of coordinates representing the upper left corner of the source. A Rect can also be passed as the destination and the topleft corner of the rectangle will be used as the position for theblit. The size of the destination rectangle does not effect the blit.
大概就是说, dest是source左上角的定位坐标
官方示例
t1=time.time()
#blitsisadictkeyedwithkey->blitflag.egBLEND_ADD.
im1.blit(img_to_blit,(0,0),None,blits[event.key])
t2=time.time()
print("onepixelis:%s:"%[im1.get_at((0,0))])
第二个
self.rect=self.rect.move(self.speed)
moves the rectangle
move(x, y) -> Rect
Returns a new rectangle that ismoved by the given offset. The x and y arguments can be any integer value, positive or negative.
根据给出的偏移返回移动过的矩形, x和y可以是任意正负整数
但是如果根据上面的定义, 你的self.rect = self.rect.move(self.speed)又是错误的,因为move(x, y)是必须给出的, 比如
a=[1,2]
f(*a)#相当于f(a[0],a[1]),即拆解可迭代的对象,且只在作为参数时可以如此使用
如果这里的self.rect = self.rect.move(self.speed)没有报错的话, 那就是让rect移动self.speed的距离, 并赋值给rect
【python】汉诺塔递归
系统自带的演示代码,可以研究一下
#!/usr/bin/envpython3
"""turtle-example-suite:
tdemo_minimal_hanoi.py
Aminimal'TowersofHanoi'animation:
Atowerof6discsistransferredfromthe
lefttotherightpeg.
Animhoquiteelegantandconcise
implementationusingatowerclass,which
isderivedfromthebuilt-intypelist.
Discsareturtleswithshape"square",but
stretchedtorectanglesbyshapesize()
---------------------------------------
ToexitpressSTOPbutton
---------------------------------------
"""
fromturtleimport*
classDisc(Turtle):
def__init__(self,n):
Turtle.__init__(self,shape="square",visible=False)
self.pu()
self.shapesize(1.5,n*1.5,2)#square-->rectangle
self.fillcolor(n/6.,0,1-n/6.)
self.st()
classTower(list):
"Hanoitower,asubclassofbuilt-intypelist"
def__init__(self,x):
"createanemptytower.xisx-positionofpeg"
self.x=x
defpush(self,d):
d.setx(self.x)
d.sety(-150+34*len(self))
self.append(d)
defpop(self):
d=list.pop(self)
d.sety(150)
returnd
defhanoi(n,from_,with_,to_):
ifn>0:
hanoi(n-1,from_,to_,with_)
to_.push(from_.pop())
hanoi(n-1,with_,from_,to_)
defplay():
onkey(None,"space")
clear()
try:
hanoi(6,t1,t2,t3)
write("pressSTOPbuttontoexit",
align="center",font=("Courier",16,"bold"))
exceptTerminator:
pass#turtledemouserpressedSTOP
defmain():
globalt1,t2,t3
ht();penup();goto(0,-225)#writerturtle
t1=Tower(-250)
t2=Tower(0)
t3=Tower(250)
#maketowerof6discs
foriinrange(6,0,-1):
t1.push(Disc(i))
#preparespartanicuserinterface;-)
write("pressspacebartostartgame",
align="center",font=("Courier",16,"bold"))
onkey(play,"space")
listen()
return"EVENTLOOP"
if__name__=="__main__":
msg=main()
print(msg)
mainloop()
Python习题(急!!!)
#-*-coding:utf-8-*-
N={0:'零',1:'壹',2:'贰',3:'叁',4:'肆',5:'伍',6:'陆',7:'柒',8:'捌',9:'玖'}
M=['亿','仟','佰','拾','万','仟','佰','拾','元']
H=['角','分']
classPrint:
def__init__(self,a,a1,a2,N):
self.a=a
self.a1=a1
self.a2=a2
self.N=N
defInt(self,M,S=''):
self.M=M
self.S=''
iflen(str(self.a1))>10:
print('输入的金额超限(超出长度)')
else:
b=abs(int(self.a1))
New=[]
forstinstr(b):
ifint(st)inself.N.keys():
New.append(self.N[int(st)])
L=self.M[-len(New):]
for(x,y)inzip(New,L):
self.S+=x+y
returnself.S
defFloat(self,H,S1=''):
self.H=H
self.S1=''
a3=int(100*self.a2)
New1=[]
forst1instr(a3):
ifint(st1)inself.N.keys():
New1.append(self.N[int(st1)])
L1=H[-len(New1):]
for(x,y)inzip(New1,L1):
self.S1+=x+y
returnself.S1
if__name__=="__main__":
whileTrue:
a=float(input('请输入金额(不超过10亿元):'))
a1=int(a)
a2=round((a-a1),2)
P=Print(a,a1,a2,N)
ifa2==0.0:
P.Int(M)
print(P.S+'0角0分')
break
else:
P.Float(H)
print(P.Int(M)+P.S1)
break
python3连接oracle报错
python3连接oracle报错 # -*- coding:utf-8 -*- #!/usr/bin/env python ''' Created on 2014年8月4日 @author: 188007 连接Oracle数据库的class ''' import os os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.ZHS16GBK' import cx_Oracle import sys class Oracle: ''' python access oracle helper tool class ''' def __init__(sVC++黑白棋
本程序提供五子棋、黑白棋双人对下的环境,以及黑白棋人机对下的功能。其界面模仿windows, 操作简便,所有操作都通过鼠标完成。 进入程序后,从game菜单可选择游戏的种类,在游戏进行过程中采用鼠标左键下子,右键悔棋。 整个源程序总共由mouse.c、timedate.c、bmp.c、bww.c、bww.prj五个文件组成,约1500余行。其中mouse.c包含鼠标相关的语句;timedate.c用于显示当前的日期与时间;bmp.c用于显示16色位图作为程序的封面以及便于中文的显示; bww.c是整个程序的核心部分,下面将就bww.c中的各个重要函数作一下简要的介绍: void init():上一篇
祝所有的老师和同学在新的一年里万事如意五福临门用英语怎么讲
下一篇
返回列表