劉任昌Python自訂函數迴圈write模式a與w
上面的程式碼
<style> h1{background-color: purple; color: white; border: 10px solid red; text-align:center; padding: 5px}
ul{background-color: green; color: white; font-size: 2em;line-height:1.5}
</style>
VS code截圖
程式碼
space, slash, backslash, cr = ' ', '/', '\\', '\n' def row1(k,m):#定義自訂函數 for i in range(1, k+1): 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(cr) def row2(r,m): 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('\n') k = input('輸入三角形長度: ') m = input('輸入橫向規格: ') n = input('往下重複次數: ') k, m, n = int(k), int(m), int(n) #將字串k轉integer整數append f = open("劉任昌.txt",'w',encoding='utf8') f.write('我是大正妹\n') print('我討厭臭男生',end='') print('我喜歡女生') print('我喜歡胖胖的女生',file=f) for i in range(n): row1(k,m) row2(k,m) f.close()
期中考筆試重點
- write寫入檔案模式mode w=write會覆蓋原有檔案, a=append接續原來檔案, x=create創立新檔案, x與w有何不同?
- write寫入檔案,預設不換行,換行'\n'
- print呈現在螢幕,預設換行,不換行end=''。
- write寫入用到英文以外的字元(一,a,b)encoding='utf8'
https://wilson11122.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://aks8704100.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://addison030.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://yun0205.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://ctz642895.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://keiime.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://hui026.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://whitexd.blogspot.com/2024/03/python.html
回覆刪除https://rrrrr-eeeee.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://kk0725.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://oscarliu1688.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://tustning.blogspot.com/2024/03/pythonwriterange.html
回覆刪除https://xi715.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://grace8166.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://chin-0908.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除https://pcai766.blogspot.com/2024/03/pythonwriteaw.html
回覆刪除作者已經移除這則留言。
回覆刪除