![]() |
Print Numbers starting at 1 vertically with separator for output numbers - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Print Numbers starting at 1 vertically with separator for output numbers (/thread-18206.html) |
Print Numbers starting at 1 vertically with separator for output numbers - Pleiades - May-09-2019 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. ![]() 262143 131071 65535 32767 16383 ![]() 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) RE: Print Numbers starting at 1 vertically with separator for output numbers - buran - May-09-2019 post your code in python tags. You should use enumerate() and some string formatting to get the desired output
RE: Print Numbers starting at 1 vertically with separator for output numbers - buran - May-09-2019 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 += 1I 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 += 1or i = 191561942608236107294793378084303638130997321548169216 result = 0 while i >= 2 : result += 1 print(f'{result: <3}) {i}') i //= 2 RE: Print Numbers starting at 1 vertically with separator for output numbers - Pleiades - May-09-2019 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) |