發表文章

目前顯示的是 10月, 2026的文章

HW03 判斷敘述式

圖片
HW03 判斷敘述式  115103136余廷宥 1. NotebookLM 2.影片 3. 學習卡 與測驗 4 . 寫1個程式需附加說明 Create a README For Github 2. Calculate the Sum of Digits of a Four-Digit Number 📌 Description This Python program reads a four-digit number from the keyboard and calculates the sum of its individual digits. For example, if the user enters 4225 , the sum of its digits is: 4 + 2 + 2 + 5 = 13 💻 Python Code num = int(input('Enter 4 digit number: ')) print('Entered number is:', num) r1 = num % 10 q1 = num // 10 r2 = q1 % 10 q2 = q1 // 10 r3 = q2 % 10 q3 = q2 // 10 r4 = q3 % 10 print('Sum of all the digits within number', num, 'is:', r1 + r2 + r3 + r4) 🧮 Logic and Formula The program uses two mathematical operators: % (Modulus): Gets the remainder, which is used to extract the last digit. // (Floor Division): Removes the last digit by dividing by 10 and keeping the integer part. For the number 4225 : Step Calculation Result 1 4225 % 10 5 2 4225 // 10 422 3 422 % 10 2 4 422 ...

HW02 運算子表達式

圖片
 HW02  運算子表達式 115103136余廷宥 1. NotebookLM 2. 3. 學習卡 和測驗 4.  寫1個程式需附加說明 Create a README For Github Here is a complete solution featuring a clean Python script and a ready-to-use GitHub README.md file. Python Code ( main.py ) Python def calculate_total_amount ( notes_100: int , notes_500: int , notes_1000: int ) -> int: """Calculates the total cash amount withdrawn from the ATM based on note counts.""" return (notes_100 * 100 ) + (notes_500 * 500 ) + (notes_1000 * 1000 ) def main (): print( "=== ATM Cash Withdrawal Calculator ===" ) try : notes_100 = int ( input ( "Enter number of ₹100 notes: " )) notes_500 = int ( input ( "Enter number of ₹500 notes: " )) notes_1000 = int ( input ( "Enter number of ₹1000 notes: " )) if notes_100 < 0 or notes_500 < 0 or notes_1000 < 0 : print( "Error: Note counts cannot be negative." ) ...

python作業

圖片
  HW01 python 基礎 115103136 余廷宥 1. NotebookLM 2. 3. 學習卡 與測驗 4.心得與體會 核心學習心得與體悟 1. 語法直覺:從「背程式碼」轉變為「用邏輯思考」 Python 的語法非常接近英語與人類邏輯(例如 for item in list: 或 if x in y: )。這種特性大大降低了入門門檻,讓學習者不必花費大量時間在處理繁瑣的語法細節(如複雜的指針或大括號),而是能專注於 解決問題的邏輯與思維模式 。 5. a = input('請輸入溫度: ') print(a) b = input('請輸入單位: ') print(b) if b == 'c' or b == 'C':     f = float(a) * 9 / 5 + 32     print(f'{float(a):.2f}C = {f:.2f}F') elif b == 'f' or b == 'F':     x = (float(a) - 32) * 5 / 9     print(f'{float(a):.2f}F = {x:.2f}C') else:     print('Error: Invalid unit') 這段 Python 程式碼的主要功能是 進行攝氏(°C)與華氏(°F)溫度的雙向轉換 。 程式碼執行邏輯解析 取得輸入並顯示 : a = input('請輸入溫度: ') :接收使用者輸入的數值(字串型態)。 b = input('請輸入單位: ') :接收使用者輸入的單位(如 c 、 C 、 f 或 F )。 單位判斷與計算 : 若單位為攝氏( c 或 C ) : 將輸入的字串 a 轉為浮點數( float )。 套用公式 $F = C \times \frac{9}{5} + 32$ 計算華氏溫度。 印出結果(保留小數點後兩位,如 25.00C = 77.00F )。 若單位為華氏( f 或 F ) : 套用公式 $C = (F - 32) \times \frac{5}{9}$ 計算攝氏溫度。 印出結果(保留小數點後兩位,如 77....