發表文章

目前顯示的是 3月, 2024的文章

蘇佑安Python自訂函數迴圈write模式a,x,w,r

圖片
上面的程式碼 <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) ...

蘇佑安python寫入write迴圈範圍range

圖片
space, slash, backslash, cr = ' ', '/', '\\', '\n' k = input('邊長: ') #輸入字串 m = input('橫向: ') k, m = int(k), int(m) f = open("難嗎.txt",'w',encoding='utf8') f.write('蘇佑安讀取檔案' + cr)#註解\n換列 for i in range(9): f.write(str(i)) f.write(cr) for i in range(1, k+1): #迴圈1到k 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) 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() 385影片

蘇佑安python檔案方法utf8

圖片
f = open("ascii.txt", "r",encoding='utf8') print(f.read()) f.close() x = "蘇佑安" f = open("ascii.txt", "r+",encoding='utf8') y = f.write(x) print(y) f.close() print(i) f = open("ascii.txt", "r+",encoding='utf8') #a代表附加append print("名稱",f.name) print("模式",f.mode) print("關閉",f.closed) f.write('蘇佑安') line = f.read() #讀取檔案f成為字串 print('檔案字串長度',len(line)) print("檔案內容",line) f.close() 影片379 影片380

蘇佑安python內建built-in函數functions迴圈loop

圖片
截圖 程式碼 print(int(10)) print(int("ff",16)) print(int('100',16)) print(int('100',8)) a = [0>1, 2>1, 3==3]#串列list使用square bracket中括號 print("是否all全真",all(a)) print("存在任何any一個真",any(a)) print("蘇佑安bin二進位輸出一到9") for i in range(10): #0 to 9進位1 print(bin(i)) for i in range(0, 200, 10): print(hex(i)) a = ('蘋果', '香蕉', '櫻桃',"durian") b = "Hello World" c = 33 d ={'蘋果', '香蕉', '櫻桃',"durian"} e=['蘋果', '香蕉', '櫻桃',"durian"] print("a元組typle", type(a)) print("b字串", type(b)) print("c整數integer", type(c)) print(type(d), type(e)) w3schools內建函數列表 Python has a set of built-in functions. Function Description abs() Returns the absolute value of a number all() Returns True if all items in an iterable object are true any() Returns True if any item in an iterable object is true ascii() Returns a readabl...