Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Print Numbers starting at 1 vertically with separator for output numbers
#1
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)
Quote
#2
post your code in python tags. You should use enumerate() and some string formatting to get the desired output
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Quote
#3
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
Pleiades likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Quote
#4
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)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  importing a list of numbers into python script barrypyth 8 357 Aug-22-2020, 09:10 PM
Last Post: barrypyth
  convert array of numbers to byte array adetheheat 3 204 Aug-13-2020, 05:09 PM
Last Post: bowlofred
  Read strings and numbers in columns from a file suvadip 4 401 Aug-11-2020, 09:37 PM
Last Post: suvadip
  output correction using print() function afefDXCTN 1 179 Aug-10-2020, 09:55 AM
Last Post: DPaul
  Quotes vs. no quotes around numbers Mark17 6 229 Aug-06-2020, 04:13 AM
Last Post: t4keheart
  Is there a way i print odd and even numbers separately? spalisetty06 5 253 Jul-21-2020, 06:48 PM
Last Post: spalisetty06
  Summing a list of numbers Oldman45 6 290 Jul-12-2020, 05:30 PM
Last Post: Oldman45
  Print output in single file using pramika loop deepakkhw 1 240 Jul-11-2020, 11:57 AM
Last Post: j.crater
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 6 2,214 Jul-01-2020, 03:53 PM
Last Post: ndc85430
  Finding line numbers starting with certain string Sutsro 3 333 Jun-27-2020, 12:36 PM
Last Post: Yoriz

Forum Jump:


Users browsing this thread: 1 Guest(s)