范雅惠python寫入write讀出read文字檔
381影片
384影片
space, slash, backslash, cr = ' ', '/', '\\', '\n'
k = input("輸入三角形邊長: ")
m = input('輸入橫向規模: ')
k ,m = int(k), int(m) #將字串改成integer
f = open("范雅惠.txt",'w',encoding="utf8")
handsome = '范雅惠呵呵'+cr
f.write(handsome)
for i in range(1, k+1):#一列i
for ii in range(m):
for j in range(k-i):
f.write(space)
f.write(slash)
for j in range(2*i-2):
f.write(space)
f.write(backslash)
for j in range(k-i):
f.write(space)
f.write('\n') #換列cr='\n'
for i in range(1, k+1):
for ii in range(m):
for j in range(i-1):
f.write(space)
f.write(backslash)
for j in range(2*k-2*i):
f.write(space)
f.write(slash)
for j in range(i-1):
f.write(space)
f.write(cr)
f.close()
评论
发表评论