Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

Flipping The Pairs

$
0
0

The program asks for a number and then prints out all the positive integer values from 1 up to the number. However, the order of the numbers is changed so that each pair or numbers is flipped. That is, 2 comes before 1, 4 before 3 and so forth. For example:

Please type in a number: 6214365
num = int(input("Please type in a number: "))r = 2t = 1while True:    if t >= num:        break    print(r)    print(t)    r += 2    t += 2

The code works fine with even numbers but then struggles with odd numbers. For example with the input 5 the result should be:

Please type in a number: 521435

But instead my output comes out as:

Please type in a number: 52143

Any help would be appreciated.


Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>