發表文章

圖片
   115103140 判斷敘述式 1. notebook 2.youtube 3. 學習卡 測驗 4. 寫1個程式需附加說明 Create a README For Github 1. Leap Year Checker 📌 Description This Python program asks the user to enter a year and checks whether the year is a leap year. A leap year has 366 days, including February 29. A normal year has 365 days. 💻 Python Code year = int(input('Enter year: ')) if (year % 4 == 0) and (not (year % 100 == 0)) or (year % 400 == 0): print('Year', year, 'is a Leap Year') else: print('Year', year, 'is not a Leap Year') 🧮 Leap Year Rules A year is a leap year if: It is divisible by 4 but not divisible by 100; or It is divisible by 400. ▶️ Example Output Enter year: 1944 Year 1944 is a Leap Year 📝 Explanation input() asks the user to enter a year. int() converts the entered value into an integer. % is the modulus operator. It returns the remainder after division. year % 4 == 0 checks whether the year is divisible by 4. not (year % 100 == 0) checks whethe...

運算子表達式

圖片
  HW02 運算子表達式   1. notebook 2.youtube 3. 學習卡 測驗 4. radius = float(input('Enter the radius of Sphere:'))  volume = (4/3) 3.14 radius**3  print(' Radius of Sphere:',radius)  print(' Volume of Spehere is: %.2f'%(volume))  Output Enter the radius of Sphere:5  Radius of Sphere: 5.0 Volume of Sphere is: 523.33 5. 這段程式碼來自教材中的練習題( Chapter_3_Solution_v1.pdf ),主要功能是 讀取使用者輸入的球體半徑,並計算且顯示該球體的體積 1 。 程式碼逐行解析: radius = float(input('Enter the radius of Sphere:')) 使用 input() 顯示提示訊息並接收使用者輸入的文字,接著透過 float() 將輸入內容轉換為**浮點數(float)**型態 1 。 volume = (4/3)*3.14*radius**3 依照球體體積公式 $V = \frac{4}{3}\pi r^3$ 進行算術計算 1 。 這裡運用了算術運算子:除法 / 、乘法 * 以及 次方運算子 ** ( radius**3 代表半徑的 3 次方) 1 。 print(' Radius of Sphere:',radius) 印出輸入的半徑數值 1 。 print(' Volume of Spehere is: %.2f'%(volume)) 使用 % 格式化字串語法,其中的 %.2f 將浮點數體積格式化並四捨五入至小數點後兩位 1 。 執行輸出分析: 使用者輸入半徑 5 後,系統將其轉換為 5.0 進行顯示 1 。 代入公式計算: $\frac{4}{3} \times 3.14 \times 5^3 = 1.3333... \times 3.14 \times 125 \approx 523.333...$ 1...
圖片
     HW #01 Python 環境建立和Hello World 1. notebook 2. youtube 3. 學習卡 與測驗 4. 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') 5. 哈佛大學做的cs50x,讓我學python更方便