AU Fundamentals of Python Programming

Ex2-1(練習2-1):輸入攝氏溫度轉成華氏溫度

\[FDegree = CDegree \times \frac{9}{5} + 32\]

Step 1: 宣告一個攝氏溫度的變數

CDegree = 0.0
print(CDegree)
0.0

Step 2: 輸入攝氏溫度的值

CDegree =             #<-?
CDegree = float(CDegree)
  File "/tmp/ipykernel_765/2248684130.py", line 1
    CDegree =             #<-?
                          ^
SyntaxError: invalid syntax

Step 3: 計算華氏溫度

FDegree =             #<-?
print(FDegree)

Ex2-2(練習2-2):計算BMI(Body Mass Index) 身體質量指數

\[BMI = \frac{體重_{公斤}}{身高_{公尺}^2}\]
\[BMI = \frac{weight_{kg}}{height_{m}^2}\]

Step 4: 宣告二個變數:體重和身高

weight = 1.0
height = 1.0
print("Weight = ", weight, " Height = ", height,)

Step 5: 輸入體重和身高

weight = input("Weight (kg):")
height =           #<-?
weight = float(weight)
height =           #<-?

Step 6: 計算BMI

bmi =            #<-?
print("BMI=", bmi);