@zy-0815
2016-09-25T18:48:54.000000Z
字数 1984
阅读 1226
L1:在屏幕上让你的英文名字水平移动起来
L2:作业L2 在80*80点阵上用字符拼出你想画的东西,并让它旋转起来,希望脑洞大开!(比如字符、火柴人、火箭等等)
In this text,we are going to talk about a method to move a certain name horizontally in the IPython shell.
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.
L1:
x='1'
d={'1':' '*1 ,'2':' '*2,'3':' '*3,'4':' '*4,'5':' '*4,'6':' '*4,'7':' '*4,'8':' '*4}
import sys
import time
times=input('Please input the times you want the name to move horiziontally')
for y in range(times):
for x in ['1','2','3','4','5','6','7','8']:
print d[x],'##### #######'
print d[x],' # #'
print d[x],' # #'
print d[x],' # #'
print d[x],'##### #'
print('\n')
time.sleep(0.3)
sys.stderr.write("\x1b[2J\x1b[H")
L2:
x='1'
d={'1':' '}
import time
import math
import sys
import os
k=0
j=1
for x in range(2):
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]:
i=os.system('cls')
print ('\n')*int(math.sin(k)*5+6)
print d['1']*int(math.cos(k)*25+30),'##### #######'
print d['1']*int(math.cos(k)*25+30),' # #'
print d['1']*int(math.cos(k)*25+30),' # #'
print d['1']*int(math.cos(k)*25+30),' # #'
print d['1']*int(math.cos(k)*25+30),'##### #'
time.sleep(0.3)
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.
L1:
L2:
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)