前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python练习题-day1

python练习题-day1

作者头像
郭耀华
发布2019-10-23 14:31:15
5100
发布2019-10-23 14:31:15
举报
文章被收录于专栏:郭耀华‘s Blog郭耀华‘s Blog

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

代码语言:javascript
复制
count=0
while count<10:
    count+=1
    if count==7:
        continue
    print(count)

2.求1-100所有数的和

代码语言:javascript
复制
sum=0
for i in range(101):
    sum+=i
print(sum)

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

代码语言:javascript
复制
li=[]
for i in range(1,101):
    if i%2==1:
        li.append(i)
print(li)

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

代码语言:javascript
复制
li=[]
for i in range(1,101):
    if i%2==0:
        li.append(i)
print(li)

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

代码语言:javascript
复制
sum=0
for i in range(100):
    if i %2 ==0:
        sum-=i
    if i%2==1:
        sum+=i
print(sum)

#方法2
sum=0
j=1
for i in range(1,100):
    sum+=i*j
    j=-j
print(sum)

6.用户登录,三次机会重试

代码语言:javascript
复制
count=0
while True:
    uname="myfu"
    password="123"
    u,p=input("input your name and password:").split()
    count+=1
    if uname ==u and password ==p:
        exit("login success")
    else:
        if count==3:
            exit("three times error input,your count is locked")
        else:
            print("error username or password ,pls try again,%s time last"%(3-count))
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-01-10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.使用while循环输入 1 2 3 4 5 6 8 9 10
  • 5.求1-2+3-4+5 ... 99的所有数的和
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档