I need to print the numbers 0-250 in binary efficiently
So far I have tried the code: "{0:bn}".function(
Does anyone have an idea how I would use this code or any suggestions of different that i can use to print the numbers 0-250 in binary.
I need to print the numbers 0-250 in binary efficiently
So far I have tried the code: "{0:bn}".function(
Does anyone have an idea how I would use this code or any suggestions of different that i can use to print the numbers 0-250 in binary.
in python bin
function can do that:
>>> bin(2)
'0b10' # value produced by bin is prefixed with 0b, it indicates valid python binary format
>>> bin(4)
'0b100'
>>> bin(100)
'0b1100100'
you can also use format:
>>> "{:b}".format(10)
'1010'
try like this: using bin
[bin(x) for x in range(251)] # produces list of binary from 0-250
using format:
["{:b}".format(x) for x in range(251)]
you can print like this:
for x in range(251):
print(bin(x))
or:
for x in range(251):
print("{:b}".fromat(x))