[关闭]
@ibilis 2016-09-25T14:16:41.000000Z 字数 4497 阅读 668

作业三

计算物理


1.摘要

在课程主页上复习这两次课程的内容,初步掌握python和matplotlib的语法规则,为接下来的课程做好准备

2.正文

1.作业L1 在屏幕上让你的英文名字水平移动起来

1.代码

  1. import os
  2. import time
  3. def benpao():
  4. for i in range(30):
  5. print('dou wei\n')
  6. print(' '*i+' ___')
  7. print(' '*i+' /======/')
  8. print(' '*i+' ____ // \___ ,/')
  9. print(' '*i+' | \\ // :, ./')
  10. print(' '*i+' |_______|__|_// ;:; /')
  11. print(' '*i+' |_______|__|_// ;:; /')
  12. print(' '*i+' _L_____________\o ;;;/')
  13. print(' '*i+'____(CCCCCCCCCCCCCC)____________-/_____________________')
  14. time.sleep( 0.2 )
  15. os.system("cls")
  16. benpao()

2.结果

before
20160925220927.png
after
20160925220956.png

2.作业L2 在80*80点阵上用字符拼出你想画的东西,并让它旋转起来,希望脑洞大开

1.代码

  1. import os
  2. import time
  3. a1=' '*2+'#'+' '*2
  4. a2=' '+'#'+' '+'#'+' '
  5. a3='#'+' '*3+'#'
  6. a4='#'*5
  7. a5='#'+' '*3+'#'
  8. b1='#'*4+' '
  9. b2='#'+' '*3+'#'
  10. b3='#'*4+' '
  11. b4='#'+' '*3+'#'
  12. b5='#'*4+' '
  13. c1='#'*5
  14. c2='#'+' '*4
  15. c3='#'+' '*4
  16. c4='#'+' '*4
  17. c5='#'*5
  18. d1='#'*4+' '
  19. d2='#'+' '*3+'#'
  20. d3='#'+' '*3+'#'
  21. d4='#'+' '*3+'#'
  22. d5='#'*4+' '
  23. e1='#'*5
  24. e2='#'+' '*4
  25. e3='#'*5
  26. e4='#'+' '*4
  27. e5='#'*5
  28. f1='#'*5
  29. f2='#'+' '*4
  30. f3='#'*5
  31. f4='#'+' '*4
  32. f5='#'+' '*4
  33. g1='#'*5
  34. g2='#'+' '*4
  35. g3='#'+' '+'#'*3
  36. g4='#'+' '*3+'#'
  37. g5='#'*5
  38. h1='#'+' '*3+'#'
  39. h2='#'+' '*3+'#'
  40. h3='#'*5
  41. h4='#'+' '*3+'#'
  42. h5='#'+' '*3+'#'
  43. i1='#'*5
  44. i2=' '*2+'#'+' '*2
  45. i3=' '*2+'#'+' '*2
  46. i4=' '*2+'#'+' '*2
  47. i5='#'*5
  48. j1='#'*5
  49. j2=' '*2+'#'+' '*2
  50. j3=' '*2+'#'+' '*2
  51. j4='#'+' '+'#'+' '*2
  52. j5=' '+'#'*2+' '*2
  53. k1='# ##'
  54. k2='# # '
  55. k3='## '
  56. k4='# # '
  57. k5='# ##'
  58. l1='# '
  59. l2='# '
  60. l3='# '
  61. l4='# '
  62. l5='#####'
  63. m1='#####'
  64. m2='# # #'
  65. m3='# # #'
  66. m4='# # #'
  67. m5='# # #'
  68. n1='# #'
  69. n2='## #'
  70. n3='# # #'
  71. n4='# ##'
  72. n5='# ##'
  73. o1=' ### '
  74. o2='# #'
  75. o3='# #'
  76. o4='# #'
  77. o5=' ### '
  78. p1='#### '
  79. p2='# #'
  80. p3='#### '
  81. p4='# '
  82. p5='# '
  83. q1='#### '
  84. q2='# # '
  85. q3='# ## '
  86. q4='#### '
  87. q5=' #'
  88. r1='#### '
  89. r2='# #'
  90. r3='#### '
  91. r4='# # '
  92. r5='# ##'
  93. s1='#####'
  94. s2='# '
  95. s3='#####'
  96. s4=' #'
  97. s5='#####'
  98. t1='#####'
  99. t2=' # '
  100. t3=' # '
  101. t4=' # '
  102. t5=' # '
  103. u1='# #'
  104. u2='# #'
  105. u3='# #'
  106. u4='# #'
  107. u5='#####'
  108. v1='# #'
  109. v2='# #'
  110. v3=' # # '
  111. v4=' # # '
  112. v5=' # '
  113. w1='# # #'
  114. w2='# # #'
  115. w3='# # #'
  116. w4='# # #'
  117. w5='#####'
  118. x1='# #'
  119. x2=' # # '
  120. x3=' # '
  121. x4=' # # '
  122. x5='# #'
  123. y1='# #'
  124. y2=' # # '
  125. y3=' # '
  126. y4=' # '
  127. y5=' # '
  128. z1='#####'
  129. z2=' # '
  130. z3=' # '
  131. z4=' # '
  132. z5='#####'
  133. wu1=' '
  134. wu2=' '
  135. wu3=' '
  136. wu4=' '
  137. wu5=' '
  138. #use list to define each single letter
  139. aa=[a1,a2,a3,a4,a5]
  140. bb=[b1,b2,b3,b4,b5]
  141. cc=[c1,c2,c3,c4,c5]
  142. dd=[d1,d2,d3,d4,d5]
  143. ee=[e1,e2,e3,e4,e5]
  144. ff=[f1,f2,f3,f4,f5]
  145. gg=[g1,g2,g3,g4,g5]
  146. hh=[h1,h2,h3,h4,h5]
  147. ii=[i1,i2,i3,i4,i5]
  148. jj=[j1,j2,j3,j4,j5]
  149. kk=[k1,k2,k3,k4,k5]
  150. ll=[l1,l2,l3,l4,l5]
  151. mm=[m1,m2,m3,m4,m5]
  152. nn=[n1,n2,n3,n4,n5]
  153. oo=[o1,o2,o3,o4,o5]
  154. pp=[p1,p2,p3,p4,p5]
  155. qq=[q1,q2,q3,q4,q5]
  156. rr=[r1,r2,r3,r4,r5]
  157. ss=[s1,s2,s3,s4,s5]
  158. tt=[t1,t2,t3,t4,t5]
  159. uu=[u1,u2,u3,u4,u5]
  160. vv=[v1,v2,v3,v4,v5]
  161. ww=[w1,w2,w3,w4,w5]
  162. xx=[x1,x2,x3,x4,x5]
  163. yy=[y1,y2,y3,y4,y5]
  164. zz=[z1,z2,z3,z4,z5]
  165. wu=[wu1,wu2,wu3,wu4,wu5]
  166. #use dic to show the connection between letter and pattern
  167. engdic={'a':aa,'b':bb,'c':cc,'d':dd,'e':ee,'f':ff,'g':gg,'h':hh,
  168. 'i':ii,'j':jj,'k':kk,'l':ll,'m':mm,'n':nn,'o':oo,'p':pp,'q':qq,
  169. 'r':rr,'s':ss,'t':tt,'u':uu,'v':vv,'w':ww,'x':xx,'y':yy,'z':zz,' ':wu}
  170. #define the output of each line
  171. def line0(x,s):
  172. li=list(s)
  173. length=len(li)
  174. line_0=''
  175. for i in li:
  176. line_0=line_0+' '+engdic[i][0]
  177. return '|'+(x[0]-1)*' ' + line_0 + (61-x[0]-length)*' '+'|'
  178. def line1(x,s):
  179. li=list(s)
  180. length=len(li)
  181. line_1=''
  182. for i in li:
  183. line_1=line_1+' '+engdic[i][1]
  184. return '|'+(x[0]-1)*' ' + line_1 + (61-x[0]-length)*' '+'|'
  185. def line2(x,s):
  186. li=list(s)
  187. length=len(li)
  188. line_2=''
  189. for i in li:
  190. line_2=line_2+' '+engdic[i][2]
  191. return '|'+(x[0]-1)*' ' + line_2 + (61-x[0]-length)*' '+'|'
  192. def line3(x,s):
  193. li=list(s)
  194. length=len(li)
  195. line_3=''
  196. for i in li:
  197. line_3=line_3+' '+engdic[i][3]
  198. return '|'+(x[0]-1)*' ' + line_3 + (61-x[0]-length)*' '+'|'
  199. def line4(x,s):
  200. li=list(s)
  201. length=len(li)
  202. line_4=''
  203. for i in li:
  204. line_4=line_4+' '+engdic[i][4]
  205. return '|'+(x[0]-1)*' ' + line_4 + (61-x[0]-length)*' '+'|'
  206. #define the function to draw a single picture
  207. def draw(x,y,s):
  208. for i in range(3):
  209. print
  210. print 40*' '+'-'*len(line0(x,s))
  211. for up in range(y[0]-1):
  212. print
  213. print 40*' '+line0(x,s)
  214. print 40*' '+line1(x,s)
  215. print 40*' '+line2(x,s)
  216. print 40*' '+line3(x,s)
  217. print 40*' '+line4(x,s)
  218. for down in range(26-y[0]):
  219. print
  220. print 40*' '+'-'*len(line0(x,s))
  221. #functions to make block move
  222. def move_ul():
  223. x[0]=x[0]-1
  224. y[0]=y[0]-1
  225. def move_ur():
  226. x[0]=x[0]+1
  227. y[0]=y[0]-1
  228. def move_dl():
  229. x[0]=x[0]-1
  230. y[0]=y[0]+1
  231. def move_dr():
  232. x[0]=x[0]+1
  233. y[0]=y[0]+1
  234. #define the way to change direction
  235. def change(x,y,count):
  236. if (x[0],y[0]) == (1,1) and count[0] == 0:
  237. count[0]=3
  238. if (x[0],y[0]) == (61-len(s),1) and count[0] == 1:
  239. count[0]=2
  240. if (x[0],y[0]) == (1,26) and count[0] == 2:
  241. count[0]=1
  242. if (x[0],y[0]) == (61-len(s),26) and count[0] == 3:
  243. count[0]=0
  244. if y[0] == 1:
  245. if count[0] == 1:
  246. count[0] = 3
  247. if count[0] == 0:
  248. count[0] = 2
  249. if y[0] == 26:
  250. if count[0] == 3:
  251. count[0] = 1
  252. if count[0] == 2:
  253. count[0] = 0
  254. if x[0] == 1:
  255. if count[0] == 2:
  256. count[0] = 3
  257. if count[0] == 0:
  258. count[0] = 1
  259. if x[0] == 61-len(s):
  260. if count[0] == 1:
  261. count[0] = 0
  262. if count[0] == 3:
  263. count[0] = 2
  264. def run():
  265. while True:
  266. draw(x,y,s)
  267. change(x,y,count)
  268. if count[0] == 0:
  269. move_ul()
  270. elif count[0] == 1:
  271. move_ur()
  272. elif count[0] == 2:
  273. move_dl()
  274. elif count[0] == 3:
  275. move_dr()
  276. time.sleep(0.2)
  277. i=os.system('cls')
  278. x = [1]
  279. y = [1]
  280. count = [0]
  281. s=raw_input('What do you want to show? ')
  282. run()

2.运行结果

before
20160925212158.png
after
20160925212138.png

3.感谢吴雨桥学长及吴帆帆同学

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注