why do molecules and ions with the same number of atoms and valence electrons have the same or similar molecular shape?

Are you asking about ions formed from a given molecule? Other than that, there is similarity only in molecules and ions with similar molecular geometries based on the VSEPR or Molecular Orbital theories of molecular geometry.