码迷,mamicode.com
首页 > 其他好文 > 详细

while循环

时间:2018-03-28 15:44:51      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:跳过   odi   continue   utf-8   while循环   pos   循环   highlight   打印   

求100之和

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
i = 0
sum = 0
while i < 100:
    i = i + 1
    sum = sum + i
    print(sum)

  

打印1-100跳过7

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
i = 0
while i < 10:
    i = i + 1
    if i == 7:
        pass
    else:
        print(i)

  

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
i = 1
while i < 10:
    i = i + 1
    if i == 7:
        continue
    print(i)

打印奇偶数

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
i = 0
while i < 100:
    i = i + 1
    if i%2 == 0:
        print("偶数", i)
    else:
        print("奇数", i)

  

 

while循环

标签:跳过   odi   continue   utf-8   while循环   pos   循环   highlight   打印   

原文地址:https://www.cnblogs.com/astrotrain/p/8663696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!