(a)
print('{:s} = {:.3e} {:s}'.format(kB_symb, kB, kB_units))
(b)
print('G = {:18.16f} {:s}'.format(G, G_units))
(c)
fmt = '{:4s} = {:11.4e} {:s}\n'*4
print(fmt.format('kB', kB, kB_units, 'mu_e', mu_e, mu_e_units, 'N_A', N_A, N_A_units,
'c', c, c_units))
(d)
print('=== {:^31s} ==='.format('G = {0:+9.2E} [{1:>9s}]'.format(G,G_units)))
print('=== {:^31s} ==='.format('\u03BCe = {0:+9.2E [{1:>9s}]'
.format(mu_e,mu_e_units)))
(e)
# The number of digits in the uncertainty to output
nsd_digits = 2
# Separate our constant into mantissa * 10^exponent
exponent = int(math.floor(math.log10(abs(G))))
mantissa = G * 10**(-exponent)
# The uncertainty digits relative to the same exponent
sd = G_unc * 10**(-exponent)
# The number of decimal places to output
dp = int(-math.log(sd,10))+nsd_digits
# The uncertainty digits as an integer
sd_digits = int(round(sd*10**dp))
print('G = {mantissa:.{dp:d}f}({sd_digits:d})e{exponent:d} {units:s}'
.format(mantissa=mantissa, dp=dp, sd_digits=sd_digits,
exponent=exponent, units=G_units))
produces
G = 6.67430(15)e-11 Nm^2/kg^2
(and similarly for $\mu_e$).