In [1]:
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display,Math
In [2]:
display(Math('10^{-2} = 0.01'))
display(Math('10^{-1} = 0.1'))
display(Math('10^{0} = 1'))
display(Math('10^{1} = 10'))
display(Math('10^{2} = 100'))
$\displaystyle 10^{-2} = 0.01$
$\displaystyle 10^{-1} = 0.1$
$\displaystyle 10^{0} = 1$
$\displaystyle 10^{1} = 10$
$\displaystyle 10^{2} = 100$
In [3]:
print('Scientific notation')
display(Math('10,021: 1\\times10^{4} \\quad 1e+04'))
display(Math('2,119: 2\\times10^{3} \\quad 2e+03'))
display(Math('0.034: 3\\times10^{-2} \\quad 3e-02'))
Scientific notation
$\displaystyle 10,021: 1\times10^{4} \quad 1e+04$
$\displaystyle 2,119: 2\times10^{3} \quad 2e+03$
$\displaystyle 0.034: 3\times10^{-2} \quad 3e-02$
In [4]:
x = 3984573945

display(Math('3.984574\\times10^{9}'))
print('{:,e}'.format(x))
print('{:,d}'.format(x))
print('%e' %x)
print('%.2e' %x)
$\displaystyle 3.984574\times10^{9}$
3.984574e+09
3,984,573,945
3.984574e+09
3.98e+09
In [5]:
s = '%e' %x
print(s)
print(type(s))
print(s[-2:])
3.984574e+09
<class 'str'>
09

Exercise

In [6]:
num = 2342

print('10**np.log10(abs(num)): ' + str(10**np.log10(abs(num))))

orderOfMag = int(np.floor(np.log10(abs(num))))
print('orderOfMag: ' + str(orderOfMag))

numstr = '{:,e}'.format(num)
print('numstr: ' + str(numstr))

wheredot = numstr.find('.')
print('wheredot: ' + str(wheredot))

scinot = numstr[:wheredot]
print('scinot: ' + str(scinot))

display(Math('%s \\text{ is } %s \\text { orders of magnitude } \\approx %s \\times 10^{%g}' \
             %(num, orderOfMag,scinot,orderOfMag)))
10**np.log10(abs(num)): 2341.9999999999995
orderOfMag: 3
numstr: 2.342000e+03
wheredot: 1
scinot: 2
$\displaystyle 2342 \text{ is } 3 \text { orders of magnitude } \approx 2 \times 10^{3}$