@ibilis
2016-09-25T14:16:41.000000Z
字数 4497
阅读 668
计算物理
在课程主页上复习这两次课程的内容,初步掌握python和matplotlib的语法规则,为接下来的课程做好准备
import osimport timedef benpao():for i in range(30):print('dou wei\n')print(' '*i+' ___')print(' '*i+' /======/')print(' '*i+' ____ // \___ ,/')print(' '*i+' | \\ // :, ./')print(' '*i+' |_______|__|_// ;:; /')print(' '*i+' |_______|__|_// ;:; /')print(' '*i+' _L_____________\o ;;;/')print(' '*i+'____(CCCCCCCCCCCCCC)____________-/_____________________')time.sleep( 0.2 )os.system("cls")benpao()
before
after

import osimport timea1=' '*2+'#'+' '*2a2=' '+'#'+' '+'#'+' 'a3='#'+' '*3+'#'a4='#'*5a5='#'+' '*3+'#'b1='#'*4+' 'b2='#'+' '*3+'#'b3='#'*4+' 'b4='#'+' '*3+'#'b5='#'*4+' 'c1='#'*5c2='#'+' '*4c3='#'+' '*4c4='#'+' '*4c5='#'*5d1='#'*4+' 'd2='#'+' '*3+'#'d3='#'+' '*3+'#'d4='#'+' '*3+'#'d5='#'*4+' 'e1='#'*5e2='#'+' '*4e3='#'*5e4='#'+' '*4e5='#'*5f1='#'*5f2='#'+' '*4f3='#'*5f4='#'+' '*4f5='#'+' '*4g1='#'*5g2='#'+' '*4g3='#'+' '+'#'*3g4='#'+' '*3+'#'g5='#'*5h1='#'+' '*3+'#'h2='#'+' '*3+'#'h3='#'*5h4='#'+' '*3+'#'h5='#'+' '*3+'#'i1='#'*5i2=' '*2+'#'+' '*2i3=' '*2+'#'+' '*2i4=' '*2+'#'+' '*2i5='#'*5j1='#'*5j2=' '*2+'#'+' '*2j3=' '*2+'#'+' '*2j4='#'+' '+'#'+' '*2j5=' '+'#'*2+' '*2k1='# ##'k2='# # 'k3='## 'k4='# # 'k5='# ##'l1='# 'l2='# 'l3='# 'l4='# 'l5='#####'m1='#####'m2='# # #'m3='# # #'m4='# # #'m5='# # #'n1='# #'n2='## #'n3='# # #'n4='# ##'n5='# ##'o1=' ### 'o2='# #'o3='# #'o4='# #'o5=' ### 'p1='#### 'p2='# #'p3='#### 'p4='# 'p5='# 'q1='#### 'q2='# # 'q3='# ## 'q4='#### 'q5=' #'r1='#### 'r2='# #'r3='#### 'r4='# # 'r5='# ##'s1='#####'s2='# 's3='#####'s4=' #'s5='#####'t1='#####'t2=' # 't3=' # 't4=' # 't5=' # 'u1='# #'u2='# #'u3='# #'u4='# #'u5='#####'v1='# #'v2='# #'v3=' # # 'v4=' # # 'v5=' # 'w1='# # #'w2='# # #'w3='# # #'w4='# # #'w5='#####'x1='# #'x2=' # # 'x3=' # 'x4=' # # 'x5='# #'y1='# #'y2=' # # 'y3=' # 'y4=' # 'y5=' # 'z1='#####'z2=' # 'z3=' # 'z4=' # 'z5='#####'wu1=' 'wu2=' 'wu3=' 'wu4=' 'wu5=' '#use list to define each single letteraa=[a1,a2,a3,a4,a5]bb=[b1,b2,b3,b4,b5]cc=[c1,c2,c3,c4,c5]dd=[d1,d2,d3,d4,d5]ee=[e1,e2,e3,e4,e5]ff=[f1,f2,f3,f4,f5]gg=[g1,g2,g3,g4,g5]hh=[h1,h2,h3,h4,h5]ii=[i1,i2,i3,i4,i5]jj=[j1,j2,j3,j4,j5]kk=[k1,k2,k3,k4,k5]ll=[l1,l2,l3,l4,l5]mm=[m1,m2,m3,m4,m5]nn=[n1,n2,n3,n4,n5]oo=[o1,o2,o3,o4,o5]pp=[p1,p2,p3,p4,p5]qq=[q1,q2,q3,q4,q5]rr=[r1,r2,r3,r4,r5]ss=[s1,s2,s3,s4,s5]tt=[t1,t2,t3,t4,t5]uu=[u1,u2,u3,u4,u5]vv=[v1,v2,v3,v4,v5]ww=[w1,w2,w3,w4,w5]xx=[x1,x2,x3,x4,x5]yy=[y1,y2,y3,y4,y5]zz=[z1,z2,z3,z4,z5]wu=[wu1,wu2,wu3,wu4,wu5]#use dic to show the connection between letter and patternengdic={'a':aa,'b':bb,'c':cc,'d':dd,'e':ee,'f':ff,'g':gg,'h':hh,'i':ii,'j':jj,'k':kk,'l':ll,'m':mm,'n':nn,'o':oo,'p':pp,'q':qq,'r':rr,'s':ss,'t':tt,'u':uu,'v':vv,'w':ww,'x':xx,'y':yy,'z':zz,' ':wu}#define the output of each linedef line0(x,s):li=list(s)length=len(li)line_0=''for i in li:line_0=line_0+' '+engdic[i][0]return '|'+(x[0]-1)*' ' + line_0 + (61-x[0]-length)*' '+'|'def line1(x,s):li=list(s)length=len(li)line_1=''for i in li:line_1=line_1+' '+engdic[i][1]return '|'+(x[0]-1)*' ' + line_1 + (61-x[0]-length)*' '+'|'def line2(x,s):li=list(s)length=len(li)line_2=''for i in li:line_2=line_2+' '+engdic[i][2]return '|'+(x[0]-1)*' ' + line_2 + (61-x[0]-length)*' '+'|'def line3(x,s):li=list(s)length=len(li)line_3=''for i in li:line_3=line_3+' '+engdic[i][3]return '|'+(x[0]-1)*' ' + line_3 + (61-x[0]-length)*' '+'|'def line4(x,s):li=list(s)length=len(li)line_4=''for i in li:line_4=line_4+' '+engdic[i][4]return '|'+(x[0]-1)*' ' + line_4 + (61-x[0]-length)*' '+'|'#define the function to draw a single picturedef draw(x,y,s):for i in range(3):print 40*' '+'-'*len(line0(x,s))for up in range(y[0]-1):print 40*' '+line0(x,s)print 40*' '+line1(x,s)print 40*' '+line2(x,s)print 40*' '+line3(x,s)print 40*' '+line4(x,s)for down in range(26-y[0]):print 40*' '+'-'*len(line0(x,s))#functions to make block movedef move_ul():x[0]=x[0]-1y[0]=y[0]-1def move_ur():x[0]=x[0]+1y[0]=y[0]-1def move_dl():x[0]=x[0]-1y[0]=y[0]+1def move_dr():x[0]=x[0]+1y[0]=y[0]+1#define the way to change directiondef change(x,y,count):if (x[0],y[0]) == (1,1) and count[0] == 0:count[0]=3if (x[0],y[0]) == (61-len(s),1) and count[0] == 1:count[0]=2if (x[0],y[0]) == (1,26) and count[0] == 2:count[0]=1if (x[0],y[0]) == (61-len(s),26) and count[0] == 3:count[0]=0if y[0] == 1:if count[0] == 1:count[0] = 3if count[0] == 0:count[0] = 2if y[0] == 26:if count[0] == 3:count[0] = 1if count[0] == 2:count[0] = 0if x[0] == 1:if count[0] == 2:count[0] = 3if count[0] == 0:count[0] = 1if x[0] == 61-len(s):if count[0] == 1:count[0] = 0if count[0] == 3:count[0] = 2def run():while True:draw(x,y,s)change(x,y,count)if count[0] == 0:move_ul()elif count[0] == 1:move_ur()elif count[0] == 2:move_dl()elif count[0] == 3:move_dr()time.sleep(0.2)i=os.system('cls')x = [1]y = [1]count = [0]s=raw_input('What do you want to show? ')run()
before
after
