条件判断

 1 age = 6
 2 if age>=18:
 3     print('Your age is ',age)
 4     print('adult')
 5 elif age>=6:
 6     print('Your age is ',age)
 7     print('teenager')
 8 else:
 9     print('kid')
10 
11 #只要x是非零数值、非空字符串、非空list等,就判断为True,否则为False。
12 x1 = 1
13 if x1:
14     print('Good_1')
15 else:
16     print('bad_1')
17 
18 x2 = 'a'
19 if x2:
20     print('Good_2')
21 else:
22     print('bad_2')
23 
24 x3 =[1,2]
25 if x3:
26     print('Good_3')
27 else:
28     print('bad_3')
29 
30 x4 = []
31 if x4:
32     print('Good_4')
33 else:
34     print('bad_4')
35 
36 x5 = 0
37 if x5:
38     print('Good_5')
39 else:
40     print('Bad_5')
41 
42 x6 = ''
43 if x6:
44     print('Good_6')
45 else:
46     print('Bad_6')
47 
48 x7 = ()
49 if x7:
50     print('Good_7')
51 else:
52     print('Bad_7')
53 
54 
55 # #input()
56 # birth = int(input('Enter your birth:'))
57 # # birth = input('Enter your birth:')  #TypeError: '>' not supported between instances of 'str' and 'int'
58 # if birth>2000:
59 #     print('00后')
60 # else:
61 #     print('00前')
62 '''
63 小明身高1.75,体重80.5kg。请根据BMI公式(体重除以身高的平方)帮小明计算他的BMI指数,并根据BMI指数:
64 
65     低于18.5:过轻
66     18.5-25:正常
67     25-28:过重
68     28-32:肥胖
69     高于32:严重肥胖
70 
71 用if-elif判断并打印结果:
72 '''
73 height = float(input('Enter your height: '))
74 weight = float(input('Enter your weight: '))
75 BMI = weight/(height*height)
76 if BMI<18.5:
77     print('过轻')
78 if 18.5<=BMI<25:
79     print('正常')
80 if 25<=BMI<28:
81     print('过重')
82 if 28<=BMI<32:
83     print('肥胖')
84 if BMI>=32:
85     print('严重肥胖')
86 
87     # 低于18.5:过轻
88     # 18.5-25:正常
89     # 25-28:过重
90     # 28-32:肥胖
91     # 高于32:严重肥胖
原文地址:https://www.cnblogs.com/jpr-ok/p/9329442.html