Python 基礎程式練習 Professor Wu # ====================================================== # Exercise 1: 計算1+2+....n sum = 0 n = int (input("請輸入正整數:")) for i in range(1, n+1): sum += i print(" 1 到 %d 的整數和為 %d" % (n, sum)) # ====================================================== # Exercise 2: 99乘法表 for i in range (1, 10): for j in range (1,10): product = i * j print("%d * %d = %2d " % (i,j,product), end = "") print() # ====================================================== # Exercise 3: 計算BMI BMI = 0 height = int (input("請輸入身高 (cm):")) weight = int (input("請輸入體重 (kg):")) BMI = (weight) / ((height/100)*(height/100)) print ("BMI = %f\n" % (BMI)) if BMI < 18.5: print("你過瘦了!") if BMI >=18.5 and BMI <24: print("體重標準!") if BMI >= 24: print("體重過重!") # ======================================================