source the arrl handbook for radio communications https en wikipedia orgwikirctimeconstant description when a capacitor is connected with a potential source ac or dc it starts to charge at a general speed but when a resistor is connected in the circuit with in series to a capacitor then the capacitor charges slowly means it will take more time than usual while the capacitor is being charged the voltage is in exponential function with time resistanceohms capacitancefarads is called rctimeconstant which may also be represented as tau by using this rctimeconstant we can find the voltage at any time t from the initiation of charging a capacitor with the help of the exponential function containing rc both at charging and discharging of a capacitor find capacitor voltage at any nth second after initiating its charging examples chargingcapacitorsourcevoltage 2 resistance 9 capacitance8 4 timesec 5 0 013 chargingcapacitorsourcevoltage2 2 resistance3 5 capacitance2 4 timesec9 1 446 chargingcapacitorsourcevoltage15 resistance200 capacitance20 timesec2 0 007 chargingcapacitor20 2000 30pow10 5 4 19 975 chargingcapacitorsourcevoltage0 resistance10 0 capacitance 30 timesec3 traceback most recent call last valueerror source voltage must be positive chargingcapacitorsourcevoltage20 resistance2000 capacitance30 timesec4 traceback most recent call last valueerror resistance must be positive chargingcapacitorsourcevoltage30 resistance1500 capacitance0 timesec4 traceback most recent call last valueerror capacitance must be positive source the arrl handbook for radio communications https en wikipedia org wiki rc_time_constant description when a capacitor is connected with a potential source ac or dc it starts to charge at a general speed but when a resistor is connected in the circuit with in series to a capacitor then the capacitor charges slowly means it will take more time than usual while the capacitor is being charged the voltage is in exponential function with time resistance ohms capacitance farads is called rc timeconstant which may also be represented as τ tau by using this rc timeconstant we can find the voltage at any time t from the initiation of charging a capacitor with the help of the exponential function containing rc both at charging and discharging of a capacitor value of exp 2 718281828459 voltage in volts resistance in ohms capacitance in farads time in seconds after charging initiation of capacitor find capacitor voltage at any nth second after initiating its charging examples charging_capacitor source_voltage 2 resistance 9 capacitance 8 4 time_sec 5 0 013 charging_capacitor source_voltage 2 2 resistance 3 5 capacitance 2 4 time_sec 9 1 446 charging_capacitor source_voltage 15 resistance 200 capacitance 20 time_sec 2 0 007 charging_capacitor 20 2000 30 pow 10 5 4 19 975 charging_capacitor source_voltage 0 resistance 10 0 capacitance 30 time_sec 3 traceback most recent call last valueerror source voltage must be positive charging_capacitor source_voltage 20 resistance 2000 capacitance 30 time_sec 4 traceback most recent call last valueerror resistance must be positive charging_capacitor source_voltage 30 resistance 1500 capacitance 0 time_sec 4 traceback most recent call last valueerror capacitance must be positive
from math import exp  


def charging_capacitor(
    source_voltage: float,  
    resistance: float,  
    capacitance: float,  
    time_sec: float,  
) -> float:
    

    if source_voltage <= 0:
        raise ValueError("Source voltage must be positive.")
    if resistance <= 0:
        raise ValueError("Resistance must be positive.")
    if capacitance <= 0:
        raise ValueError("Capacitance must be positive.")
    return round(source_voltage * (1 - exp(-time_sec / (resistance * capacitance))), 3)


if __name__ == "__main__":
    import doctest

    doctest.testmod()