条件判断与循环

IF条件判断:

#示例:
age = 3
if age >= 18:
    print 'adult'
elif age >= 6:
    print 'teenager'
else:
    print 'kid'

for...in循环

#示例1
names = ['Michael', 'Bob', 'Tracy']
for name in names:
    print name

#示例2
sum = 0
for x in range(101):
    sum = sum + x
print sum

while循环

sum = 0
index = 1
while index <= 100:
    sum = sum + index
print sum

你可能感兴趣的:(条件判断与循环)