美文网首页
条件判断与循环

条件判断与循环

作者: viean | 来源:发表于2018-05-22 22:19 被阅读0次

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

相关文章

网友评论

      本文标题:条件判断与循环

      本文链接:https://www.haomeiwen.com/subject/urdjkftx.html