發表文章

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

HW03 判斷敘述式

圖片
1. NoteBook LM 2. Youtube 3.學習卡與測驗 學習卡 測驗 4.程式碼 1. Python 程式:Internet Browsing Bill Calculator 根據題目規定: 每小時:Rs 20 半小時:Rs 10 每日無限時數:Rs 100 輸入 0 代表使用無限時數方案 python # Internet Browsing Bill Calculator n = float ( input ( "Enter the number of hours spent on surfing " "(enter 0 for unlimited hours): " )) if n == 0 : print ( "Cost of Surfing is Rs 100" ) elif n > 0 : cost = n * 20 print ( "Cost of Surfing is Rs" , cost) else : print ( "Invalid number of hours. Please enter 0 or a positive number." ) 2. 程式說明(Program Explanation) input() :讓使用者輸入上網的時數。 float() :將輸入轉換成數字,支援 0.5 、 4.5 等小數時數。 if n == 0 :如果輸入 0 ,表示使用每日無限時數方案,收費 Rs 100。 elif n > 0 :如果輸入大於 0 的時數,使用「時數 × Rs 20」計算費用。 else :如果輸入負數,顯示錯誤訊息。 注意:原題的 eval(input()) 可以改成 float(input()) ,更安全,也適合這個計算程式。 3. 執行範例(Sample Output) text Enter the number of hours spent on surfing (enter 0 for unlimited hours): 4.5 Cost of...

HW02 運算子表達式 115103205

圖片
 1. NoteBook LM  2. Youtube 3.學習卡與測驗 學習卡 測驗 4.程式碼 1. Python 程式碼 檔案名稱: sphere_volume.py # Program: Calculate the Volume of a Sphere# Formula: Volume = (4/3) * 3.14 * radius^3radius = float(input("Enter the radius of Sphere: "))volume = (4 / 3) * 3.14 * radius ** 3print("Radius of Sphere:", radius)print("Volume of Sphere is: %.2f" % volume) 2. 執行結果(Output) Enter the radius of Sphere: 5 Radius of Sphere: 5.0 Volume of Sphere is: 523.33 3. 程式說明(Program Explanation) 程式碼 說明 input() 讓使用者輸入球體半徑 float() 將輸入資料轉換成浮點數 radius ** 3 計算半徑的三次方 (4 / 3) * 3.14 * radius ** 3 計算球體體積 print() 輸出計算結果 %.2f 將體積顯示到小數點後兩位 計算公式: \(V = \frac{4}{3}\pi r^3\) \(V=\frac{4}{3}\pi(\text{5.9})^3\approx \text{860.29}\) \(r\) r = 5.9 提供回饋 4. GitHub README.md 以下內容可以直接複製到 GitHub 的 README.md 檔案。 Sphere Volume Calculator Introduction This project is a simple Python program that calculates the volume of a sphere based on the radius entered by the user. Formula The formula for ca...