李家維python寫入write讀出read文字檔
a
space, slash, backslash, cr = ' ', '/', '\\', '\n' k = input("輸入三角形邊長: ") m = input('輸入橫向規模: ') k ,m = int(k), int(m) #將字串改成integer f = open("李家維.txt",'w',encoding="utf8") 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()
0321盡可能地減少空白,不要浪費版面,一定要寫心得,才能回顧、思考所學。https://willy2005940612.blogspot.com/2024/03/pythonwriteread.html
回覆刪除