MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / astable_duty_cycle

Function astable_duty_cycle

electronics/ic_555_timer.py:50–69  ·  view source on GitHub ↗

Usage examples: >>> astable_duty_cycle(resistance_1=45, resistance_2=45) 66.66666666666666 >>> astable_duty_cycle(resistance_1=356, resistance_2=234) 71.60194174757282 >>> astable_duty_cycle(resistance_1=2, resistance_2=-1) Traceback (most recent call last): ...

(resistance_1: float, resistance_2: float)

Source from the content-addressed store, hash-verified

48
49
50def astable_duty_cycle(resistance_1: float, resistance_2: float) -> float:
51 """
52 Usage examples:
53 >>> astable_duty_cycle(resistance_1=45, resistance_2=45)
54 66.66666666666666
55 >>> astable_duty_cycle(resistance_1=356, resistance_2=234)
56 71.60194174757282
57 >>> astable_duty_cycle(resistance_1=2, resistance_2=-1)
58 Traceback (most recent call last):
59 ...
60 ValueError: All values must be positive
61 >>> astable_duty_cycle(resistance_1=0, resistance_2=0)
62 Traceback (most recent call last):
63 ...
64 ValueError: All values must be positive
65 """
66
67 if resistance_1 <= 0 or resistance_2 <= 0:
68 raise ValueError("All values must be positive")
69 return (resistance_1 + resistance_2) / (resistance_1 + 2 * resistance_2) * 100
70
71
72if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected