<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def targetpop(upper_density, coul, target_cf, slsp, n_tot):
 """restriction on finding the right populations that leave the crystal field same"""

    if upper_density < 0.503: return 0.
    trypops=population_distri(upper_density, n_tot)
    slsp.set_filling(trypops)
    slsp.selfconsistency(coul,0)
    efm_free = dos_bethe_find_crystalfield(trypops, slsp.param['hopping'])
    orb_ener = slsp.param['lambda']+ slsp.quasiparticle_weight()*efm_free
    obtained_cf = orb_ener[5] - orb_ener[0]
    return target_cf - obtained_cf