You are viewing a single comment's thread. Return to all comments →
w = int(math.log(n,2))+1 for i in range(1,n+1): print("{0:{1}d} {0:{1}o} {0:{1}X} {0:{1}b}".format(i,w))
I thought it simplest to just calculate the length of the binary representation.
Note how {0: specifies the first positional argument, and {1} specifies the second for width.
{0:
Seems like cookies are disabled on this browser, please enable them to open this website
String Formatting
You are viewing a single comment's thread. Return to all comments →
I thought it simplest to just calculate the length of the binary representation.
Note how
{0:specifies the first positional argument, and {1} specifies the second for width.