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...