Python Forum

Full Version: Print Numbers starting at 1 vertically with separator for output numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
These numbers scroll vertically down my cmd screen after I hit execute from Geany. Is it possible for python to include numbers next to numbers with a separator, so I know which number to go to in the list? The imoge with the numbers below the sunglasses is what I hope for. Thanks anyone for the help.

Sad
262143
131071
65535
32767
16383

Cool
1)262143
2)131071
3)65535
4)32767
5)16383

Here is my code:

i = int(191561942608236107294793378084303638130997321548169216)
result = 0
while i >= 2 :
    print enumerate (i)
    i = i // 2
    
    result = result + 1
print (i //result)
print (result)
n = 191561942608236107294793378084303638130997321548169216//8
print (n)
post your code in python tags. You should use enumerate() and some string formatting to get the desired output
ok, it's bit different from what I expected.
i = 191561942608236107294793378084303638130997321548169216
result = 0
while i >= 2 :
    print(f'{result + 1: <3}) {i}')
    i = i // 2 # i //= 2
    result = result + 1 # result += 1
I am not sure if you would use result after you exit the loop
you may do also
i = 191561942608236107294793378084303638130997321548169216
result = 1
while i >= 2 :
    print(f'{result: <3}) {i}')
    i //= 2
    result += 1
or
i = 191561942608236107294793378084303638130997321548169216
result = 0
while i >= 2 :
    result += 1
    print(f'{result: <3}) {i}')
    i //= 2
Thanks for the quick response buran, I was playing with perfect numbers, trying to reverse engineer them. lol
The problem is python cannot handle 100 mb outputs to well when calculating.

yet this one is easy

# Mersenne Prime Hunter
i = 496
result = 1
while i >= 2 :
    print(f'{result: <3}) {i}')
    i //= 2
    result += 1
print (result/2 +.5)