嫒美直播免费版app下载-嫒美直播永久免费版下载-嫒美直播最新下载安装

當(dāng)前位置:首頁(yè) > 教育綜合 > 正文

self.noTrace_goto(x, y)什么意思

python求助 和孩子一起學(xué)編程里的一段

首先, 我不懂pygame模塊, 但是我覺(jué)得還是應(yīng)該嘗試一下

官方文檔, www點(diǎn)pygame點(diǎn)org 如果你英文好的話(huà)

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.

大概就是說(shuō), dest是source左上角的定位坐標(biāo)

官方示例

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))])

第二個(gè)

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.

根據(jù)給出的偏移返回移動(dòng)過(guò)的矩形, x和y可以是任意正負(fù)整數(shù)

但是如果根據(jù)上面的定義, 你的self.rect = self.rect.move(self.speed)又是錯(cuò)誤的,因?yàn)閙ove(x, y)是必須給出的, 比如

a=[1,2]
f(*a)#相當(dāng)于f(a[0],a[1]),即拆解可迭代的對(duì)象,且只在作為參數(shù)時(shí)可以如此使用

如果這里的self.rect = self.rect.move(self.speed)沒(méi)有報(bào)錯(cuò)的話(huà), 那就是讓rect移動(dòng)self.speed的距離, 并賦值給rect

【python】漢諾塔遞歸

系統(tǒng)自帶的演示代碼,可以研究一下

#!/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習(xí)題(急?。。。?/h3>
#-*-coding:utf-8-*-
N={0:'零',1:'壹',2:'貳',3:'叁',4:'肆',5:'伍',6:'陸',7:'柒',8:'捌',9:'玖'}
M=['億','仟','佰','拾','萬(wàn)','仟','佰','拾','元']
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('輸入的金額超限(超出長(zhǎng)度)')
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('請(qǐng)輸入金額(不超過(guò)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報(bào)錯(cuò)

python3連接oracle報(bào)錯(cuò) # -*- coding:utf-8 -*- #!/usr/bin/env python ''' Created on 2014年8月4日 @author: 188007 連接Oracle數(shù)據(jù)庫(kù)的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__(s

VC++黑白棋

本程序提供五子棋、黑白棋雙人對(duì)下的環(huán)境,以及黑白棋人機(jī)對(duì)下的功能。其界面模仿windows, 操作簡(jiǎn)便,所有操作都通過(guò)鼠標(biāo)完成。 進(jìn)入程序后,從game菜單可選擇游戲的種類(lèi),在游戲進(jìn)行過(guò)程中采用鼠標(biāo)左鍵下子,右鍵悔棋。 整個(gè)源程序總共由mouse.c、timedate.c、bmp.c、bww.c、bww.prj五個(gè)文件組成,約1500余行。其中mouse.c包含鼠標(biāo)相關(guān)的語(yǔ)句;timedate.c用于顯示當(dāng)前的日期與時(shí)間;bmp.c用于顯示16色位圖作為程序的封面以及便于中文的顯示; bww.c是整個(gè)程序的核心部分,下面將就bww.c中的各個(gè)重要函數(shù)作一下簡(jiǎn)要的介紹: void init():
展開(kāi)全文閱讀