码迷,mamicode.com
首页 > 编程语言 > 详细

python第一篇 条件循环小练习

时间:2019-05-09 13:33:45      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:小练习   col   练习   div   NPU   str   pytho   font   奇数   

输出1 2 3 4 5 6 8 9 10

#!/bin/usr/env python
n = 1;
while n<11:
    if n == 7:
        pass
    else:
        print(n)
    n = n+1
print("---end---")

输出1-100内的奇数

#!/bin/usr/env python
n = 1;
while n<101:
    if n % 2 == 0:
        pass
    else:
        print(n)
    n = n+1
print("---end---")

#!/bin/usr/env python
n = 1;
while n<101:
    print(n)
    n = n+2
print("---end---")

求1-100的和

#!/bin/usr/env python
n = 1
s = 0
while n<101:
    s += n
    n = n + 1
print(s)
print("---end---")

求1-2+3...-100的值

#!/bin/usr/env python
n = 1
s = 0
while n<101:
    if n%2==0:
        s -= n
    else:
        s += n
    n = n + 1
print(s)
print("---end---")

用户登录三次机会重试

#!/bin/usr/env python
count = 1
while count < 4:
    first = input("输入密码:")
    if first == "root":
        print("输入正确")
        break;
    else:
        count = count + 1
        if count == 4:
            print("输入超过三次")
            break;
print("---end---")

 

python第一篇 条件循环小练习

标签:小练习   col   练习   div   NPU   str   pytho   font   奇数   

原文地址:https://www.cnblogs.com/holdononedream/p/10837832.html

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