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

python基础练习题

时间:2018-05-08 23:03:15      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:python基础   inpu   print   ==   while循环   三次   bsp   and   nbsp   

1、使用while循环输入 1 2 3 4 5 6     8 9 10

count = 1
while count< 11:
    if count == 7:   
        count+=1
        continue
    print(count)
    count+=1

 

2、求1-100的所有数的和

counts = 1
num = 0
while counts <101:
    num +=counts
    counts+=1
print(num)

  

3、输出 1-100 内的所有奇数

counte = 1
while counte < 101:
    if counte % 2 == 1:
        print(counte)
    counte+=1

  

4、输出 1-100 内的所有偶数

counte = 1
while counte < 101:
    if counte % 2 != 1:
        print(counte)
    counte+=1

  

5、求1-2+3-4+5 ... 99的所有数的和

counte = 1
num = 0
num1 = 0
while counte < 100:
    if counte % 2 != 1:
        num += -counte
    else:
        num1 += counte
    counte+=1
print(num+num1)

  

6、用户登陆(三次机会重试)

count = 0
while count<3:
    count +=1
    username = input("username:")
    password = input("password:")
    if username == ‘alex‘ and password == ‘123456‘:
        print(‘登陆成功!‘)
        break
    else:
        print(‘请重试!‘)

  

python基础练习题

标签:python基础   inpu   print   ==   while循环   三次   bsp   and   nbsp   

原文地址:https://www.cnblogs.com/guobaoyuan/p/9011520.html

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