DEV Community

Guru prasanna
Guru prasanna

Posted on

1

Python - Level : 2 Tasks

Level:2 Tasks

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
Enter fullscreen mode Exit fullscreen mode

Output:

7,10,8,11,9,12,10,
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Output:

36,34,30,28,24,22,
Enter fullscreen mode Exit fullscreen mode

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


Enter fullscreen mode Exit fullscreen mode

Output:

22,21,23,22,24,23,
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

Output:

21, 9, 21, 11, 21, 13, 21, 
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

Output:

3, 4, 7, 8, 11, 12,
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

Output:

14, 28, 20, 40, 32, 64, 
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

๐Ÿ› ๏ธ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

๐Ÿ‘‹ Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay