[关闭]
@zy-0815 2016-09-25T18:48:54.000000Z 字数 1984 阅读 1236

1.Problem

L1:在屏幕上让你的英文名字水平移动起来
L2:作业L2 在80*80点阵上用字符拼出你想画的东西,并让它旋转起来,希望脑洞大开!(比如字符、火柴人、火箭等等)

2.Abstract

  In this text,we are going to talk about a method to move a certain name horizontally in the IPython shell.

3.Background Introduction

  With the preceeding knowledge of the 'for' loop and the dictionary,we are able to write a little program to make our names move horizontally with little effort.Additionally,you can input the times that you want the name to move horizontally.

4.Main L1:

L1:

  1. x='1'
  2. d={'1':' '*1 ,'2':' '*2,'3':' '*3,'4':' '*4,'5':' '*4,'6':' '*4,'7':' '*4,'8':' '*4}
  3. import sys
  4. import time
  5. times=input('Please input the times you want the name to move horiziontally')
  6. for y in range(times):
  7. for x in ['1','2','3','4','5','6','7','8']:
  8. print d[x],'##### #######'
  9. print d[x],' # #'
  10. print d[x],' # #'
  11. print d[x],' # #'
  12. print d[x],'##### #'
  13. print('\n')
  14. time.sleep(0.3)
  15. sys.stderr.write("\x1b[2J\x1b[H")

5.Main L2:

L2:

  1. x='1'
  2. d={'1':' '}
  3. import time
  4. import math
  5. import sys
  6. import os
  7. k=0
  8. j=1
  9. for x in range(2):
  10. for k in [0,0.25*math.pi,0.5*math.pi,0.6*math.pi,0.75*math.pi,1*math.pi,1.25*math.pi,1.5*math.pi,1.75*math.pi,2*math.pi,2.25*math.pi,2.5*math.pi,2.75*math.pi,3*math.pi]:
  11. i=os.system('cls')
  12. print ('\n')*int(math.sin(k)*5+6)
  13. print d['1']*int(math.cos(k)*25+30),'##### #######'
  14. print d['1']*int(math.cos(k)*25+30),' # #'
  15. print d['1']*int(math.cos(k)*25+30),' # #'
  16. print d['1']*int(math.cos(k)*25+30),' # #'
  17. print d['1']*int(math.cos(k)*25+30),'##### #'
  18. time.sleep(0.3)

6.Conclusion

  L1:We finally make it moving,but somehow a problem arises with the command"i=os.system('cls')".Here we can not clear the command in the shell and I have tried many times but it doesn't work fine on my mac.So laterly,I find another way as ''sys.stderr.write("\x1b[2J\x1b[H")''

  L2:In this section, I find that the order of os.system('cls')is only valid for the windows,not for mac.That's the reason why I choos to display my result in windows.Additionally,we use the function math.sin and math.cos to give a parameter function of a circle to let the name rotate around a point.

7.Result

L1:
捕获 06.gif-115.2kB

L2:
捕获 05.gif-465.2kB

8.Acknowledgement

1.How to think like a computer scientist – Learning with Python: Interactive Edition 2.0
2.Python Tutorial - Cai Hao
3.Zong Yue-(Provide me with the VIP in 作业部落 and PC)

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