How can I get the second column to line up perfectly using python? -


When I run the following code, then I'm trying to make the second column line completely:

  Import Mathematics X = 1.0, while X & lt; = 65536.0: Print X, '\ t \ t', math.log (x) /math.log (2.0) x = x * 2.0  

Although the three lower lines of the second column are always Tabs do an additional time in relation to previous lines, even if how many '\ t I use.

How can I fix this?

You can use str.format and create the inside row Can be:

  import math = X, 1.0 while X & lt; = 65536.0:. Print "{: 7} {}" format (x, math.log (x) /math.log (2.0)) x = x * 2,0 1,0 0,0 2.0 1,0 4,0 2 , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 64,0 6,0 128,0 7.0,06,0 8,0 512,0 9,0 1024,0 10,0 2048,0 11,0 4096,0 12,0 8192,0 13,0 16384,0 14,0 32768,0 15,0 65536,0 16,0   

or < Code> zfill () to pad zero:.

  print "{} {}" format (STR (x) .zfill (7), math.log (x) /math.log (2,0)) 00001,0 0, 0 00002,0 1,0 00004,0 2,0 00008,0 3,0 00016,0 4,0 00032,0 5,0 00064,0 6,0 00128,0 7,0 00256,0 8,0 00512 , 0,080,024,0,0,0,02048,0 11,0 04096,0 12,0 08192,0 13,0 16384,0 14,0 32768.0 15.0 65536.0 16.0  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -