the photoelectric effect is the emission of electrons when electromagnetic radiation such as light hits a material electrons emitted in this manner are called photoelectrons in 1905 einstein proposed a theory of the photoelectric effect using a concept that light consists of tiny packets of energy known as photons or light quanta each packet carries energy hv that is proportional to the frequency v of the corresponding electromagnetic wave the proportionality constant h has become known as the planck constant in the range of kinetic energies of the electrons that are removed from their varying atomic bindings by the absorption of a photon of energy hv the highest kinetic energy kmax is kmax hvw here w is the minimum energy required to remove an electron from the surface of the material it is called the work function of the surface reference https en wikipedia orgwikiphotoelectriceffect calculates the maximum kinetic energy of emitted electron from the surface if the maximum kinetic energy is zero then no electron will be emitted or given electromagnetic wave frequency is small frequency float frequency of electromagnetic wave workfunction float work function of the surface inev optionalbool pass true if values are in ev usage example maximumkineticenergy1000000 2 0 maximumkineticenergy1000000 2 true 0 maximumkineticenergy10000000000000000 2 true 39 357000000000006 maximumkineticenergy9 20 traceback most recent call last valueerror frequency can t be negative maximumkineticenergy1000 a traceback most recent call last typeerror unsupported operand types for float and str in si js in evs calculates the maximum kinetic energy of emitted electron from the surface if the maximum kinetic energy is zero then no electron will be emitted or given electromagnetic wave frequency is small frequency float frequency of electromagnetic wave work_function float work function of the surface in_ev optional bool pass true if values are in ev usage example maximum_kinetic_energy 1000000 2 0 maximum_kinetic_energy 1000000 2 true 0 maximum_kinetic_energy 10000000000000000 2 true 39 357000000000006 maximum_kinetic_energy 9 20 traceback most recent call last valueerror frequency can t be negative maximum_kinetic_energy 1000 a traceback most recent call last typeerror unsupported operand type s for float and str
PLANCK_CONSTANT_JS = 6.6261 * pow(10, -34)  
PLANCK_CONSTANT_EVS = 4.1357 * pow(10, -15)  


def maximum_kinetic_energy(
    frequency: float, work_function: float, in_ev: bool = False
) -> float:
    
    if frequency < 0:
        raise ValueError("Frequency can't be negative.")
    if in_ev:
        return max(PLANCK_CONSTANT_EVS * frequency - work_function, 0)
    return max(PLANCK_CONSTANT_JS * frequency - work_function, 0)


if __name__ == "__main__":
    import doctest

    doctest.testmod()