# PY2 AbsMag

Calculate absolute magnitude from stellar apparent visual magnitude and radial distance (LY)

```#!/usr/bin/python

import math
import sys

Mvis = float(sys.argv)
Dist = float(sys.argv)

Vabs = Mvis - 5 * (math.log10(Dist /  3.2616) -1)

print round(Vabs,3) ```

Bytes

Calculate the maximum number represented by data structures from one to eight bytes

`print '\n'.join("%i Byte = %i Bit = largest number: %i" % (j, j*8, 256**j-1) for j in (1 << i for i in range(8)))`

` `

Greek alphabet Math.py

The sun is four hundred times larger than the moon and four hundred times farther away, so they look the same size. No better evidence of a Creator. Who else would have made for us such perfect symmetry?

Actually God is off by a smidge:

```import math Diameter_moon=2159 Distance_moon=238855 Diameter_sun=864938 Distance_sun=92955807 print(math.degrees(math.atan2(Diameter_moon,Distance_moon))) print(math.degrees(math.atan2(Diameter_sun,Distance_sun)))``` Mixed

Convert improper fractions to mixed numbers with Python
``` #!/usr/bin/python```

import sys
num=int(sys.argv)
den=int(sys.argv)

print(‘ %d %d/%d’ % (num // den, num % den, den)) The quadratic formula implemented in Python

import math
import sys

a = float(sys.argv)
b = float(sys.argv)
c = float(sys.argv)

discriminant = b**2 – 4 * a * c

if discriminant >= 0:
x1=(-b+math.sqrt(discriminant))/2*a
x2=(-b-math.sqrt(discriminant))/2*a
else:
x1= complex((-b/(2*a)),math.sqrt(-discriminant)/(2*a))
x2= complex((-b/(2*a)),-math.sqrt(-discriminant)/(2*a))

if discriminant > 0:
print(“The function has two real roots: {} and {}”.format(x1,x2))
elif discriminant == 0:
print(“The function has one double root: {}”.format(x1))
else:
print(“The function has two complex roots: {} and {}”.format(x1,x2)) Seconds

Convert seconds to compound duration with #Python

```#!/usr/bin/python import sys sec=int(sys.argv) def dur(sec): t=[] for dm in (60,60,24,7): sec, m=divmod(sec,dm) t.append(m) t.append(sec) return ', '.join('%d %s' % (num,unit) for num, unit in zip(t[::-1], 'wk d hr min sec'.split()) if num)```

`print ("%7d seconds = %s" % (sec,dur(sec)))` Synodic

It takes almost 584 days for Venus to lap the Earth:

```import sys inside = float(sys.argv) outside = float(sys.argv) interim1 = inside / outside if interim1 < 1: interim1 = 1 / interim1 interim2 = 1 - interim1 print ((abs(1 / interim2) + 1) * inside)```