Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to print numbers in a specific order

I want to print numbers in a specific order. For example I want to print numbers 1 to 7

while number < 7:
number += 1
print(number)

It gives:

1 
2
3
4
5
6
7

but output I would like is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

1
2
4
3
5
6
7 

>Solution :

I can’t comment b/c my rep is so low, but this would give the desired output lol. Not sure what you would use this for but you can make a dictionary and output it in a while loop.

number = {1:1,
          2:2,
          3:4,
          4:3,
          5:5,
          6:6,
          7:7
    }

num = 1
while num < 8:
    print(number[num])
    num += 1

Gives:

1
2
4
3
5
6
7
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading