import numpy as np
import matplotlib.pyplot as plt

def Constante(a,P):
  cte = np.zeros(len(a))
  for i in range(len(a)):
    cte[i] = P[i]**2 / a[i]**3
  return cte

planetas = ['Mercurio', 'Venus', 'Tierra', 'Marte', 'Júpiter', 'Saturno', 'Urano', 'Neptuno']
a = np.array([0.39, 0.72, 1.00, 1.52, 5.20, 9.54, 19.22, 30.06])
P = np.array([0.24, 0.62, 1.00, 1.88, 11.86, 29.46, 84.0, 164.8])

cte = Constante(a,P)
for i in range(len(planetas)):
  print(planetas[i], cte[i])

print()
cte_prom = np.sum(cte) / len(cte)
print("La constante promedio es:", cte_prom)

print()
cte_prom_SI = cte_prom * 3.154e7**2 / 1.496e11**3
print("La constante promedio en SI es:", cte_prom_SI)

g = 6.67428e-11
m_sol = 4 * np.pi**2 / (g * cte_prom_SI)

print()
print("La masa del Sol es:", m_sol, "Kg")


plt.scatter(a**3,P**2)
plt.plot(a**3,P**2, color='red')
plt.xlabel('a^3')
plt.ylabel('P^2')
plt.title('Tercera Ley de Kepler')
plt.show()

