@Theodora171198 If it was possible to view The Sims 2's registry entries on a PC that it is/was installed on, you could maybe find the code there. Unfortunately, if that's not the case, you might have to purchase a new copy.
If you choose to get another one, I recommend looking for The Sims 2 Double Deluxe, as it includes the base game, as well as Nightlife EP and Celebration! SP.