-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprg1.txt
37 lines (30 loc) · 981 Bytes
/
prg1.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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("體重過重!")
# ======================================================