Python-条件、循环、

1、条件:
age = 3 if age >= 18: print 'adult' elif age >= 6: print 'teenager' else: print 'kid'
不能少了:
elif
2、循环
一种是for ...in...
names = ['Machael','Bob','Tracy']
for name in names:
  print name

range(5):生成从0开始小于5的整数。[0,1,2,3,4]

另一种是while
sum= 0
n = 99
while n > 0:
  sum = sum+n
  n = n - 2
print sum

birth = int(raw_input('birth: ')):将输入转化为整数

你可能感兴趣的:(python)