Comment

Comment by DuncanCoffee

It's because you have the radius on the denominator (I think)

  def calc_gravity(mass_1: float, mass_2: float, radius: float) -> float:
      G = 6.67408e-11
      return G * mass_1 * mass_2 / radius**2

  earth_mass = 5.972e24
  earth_radius = 6.371e6
  earth_g = calc_gravity(1.0, earth_mass, earth_radius)
  print(f"earth: {earth_g:.2f} m/s^2")

  moon_mass = 7.34767309e22
  moon_radius = 1737.4e3
  moon_g = calc_gravity(1.0, moon_mass, moon_radius)
  print(f"moon: {moon_g:.2f} m/s^2")

  print(f"earth/moon proportion: {(earth_g / moon_g):.2f}")

prints

  earth: 9.82 m/s^2
  moon: 1.62 m/s^2
  earth/moon proportion: 6.04
parent DuncanCoffee 2 months ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton