登录
首页 >  文章 >  python教程

Python - 级别:询问

来源:dev.to

时间:2024-12-02 13:42:51 423浏览 收藏

小伙伴们对文章编程感兴趣吗?是否正在学习相关知识点?如果是,那么本文《Python - 级别:询问》,就很适合你,本篇文章讲解的知识点主要包括。在之后的文章中也会多多分享相关知识点,希望对大家的知识积累有所帮助!

Python - 级别:询问

等级:2 任务

1) 7, 10, 8, 11, 9, 12, 10

# 7,10,8,11,9,12,10

no = 7

count = 0

while count < 7:
    print(no, end=",")
    if count % 2 == 0:  
        no += 3
    else:  
        no -= 2
    count += 1

输出:

7,10,8,11,9,12,10,

2) 36, 34, 30, 28, 24, 22

num = 36

diff=2

while num >= 22:
    print(num, end=",")
    if diff==2 :
        num -= diff
        diff=4
    else:
        num -= diff
        diff=2

输出:

36,34,30,28,24,22,

3) 22, 21, 23, 22, 24, 23

# 22, 21, 23, 22, 24, 23

num = 22

diff=1

while num <= 24:
    print(num, end=",")
    if diff==1 :
        num -= diff
        diff+=1
    else:
        num += diff
        diff=1


输出:

22,21,23,22,24,23,

4) 53, 53, 40, 40, 27, 27

# 53, 53, 40, 40, 27, 27

num = 53

diff=13

while num >= 27:
    print(num,num, end=",")
    if diff==13 :
        num -= diff

    else:
        break

5) 21, 9, 21, 11, 21, 13, 21

fixed_number = 21
no = 9

count = 0

while count < 7:
    if count % 2 == 0:  
        print(fixed_number, end=', ')
    else:  
        print(no, end=', ')
        no += 2  
    count += 1

输出:

21, 9, 21, 11, 21, 13, 21, 

6) 3, 4, 7, 8, 11, 12

# 3, 4, 7, 8, 11, 12
no = 3  
count = 0  


while count < 6:
    if count % 2 == 0:  
        print(no, end=', ')
    else:  
        print(no+ 1, end=', ')
        no += 4 
    count += 1

输出:

3, 4, 7, 8, 11, 12,

7) 14, 28, 20, 40, 32, 64

no = 14   
difference = 8 
count = 0 


while count < 6:
    if count % 2 == 0: 
        print(no, end=', ')
        no *= 2 
    else: 

        print(no, end=', ')
        no-=8  
    count += 1

输出:

14, 28, 20, 40, 32, 64, 

理论要掌握,实操不能落!以上关于《Python - 级别:询问》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:dev.to 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>