范雅惠Python自訂函數迴圈write模式a與w
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 ( '輸入三角
截圖清礎,但妳可以做得更好,讓截圖的空白區域減少。要多多貼上所學,順便寫心得,才能將所學內化到心理。
回复删除