# https://en.wikipedia.org/wiki/Electrical_reactance#Inductive_reactancefrom __future__ import annotationsfrom math import pidef ind_reactance(inductance: float, frequency: float, reactance: float) -> dict[str, float]:"""Calculate inductive reactance, frequency or inductance from two given electricalproperties then return name/value pair of the zero value in a Python dict.Parameters----------inductance : float with units in Henriesfrequency : float with units in Hertzreactance : float with units in Ohms>>> ind_reactance(-35e-6, 1e3, 0)Traceback (most recent call last):...ValueError: Inductance cannot be negative>>> ind_reactance(35e-6, -1e3, 0)Traceback (most recent call last):...ValueError: Frequency cannot be negative>>> ind_reactance(35e-6, 0, -1)Traceback (most recent call last):...ValueError: Inductive reactance cannot be negative>>> ind_reactance(0, 10e3, 50){'inductance': 0.0007957747154594767}>>> ind_reactance(35e-3, 0, 50){'frequency': 227.36420441699332}>>> ind_reactance(35e-6, 1e3, 0){'reactance': 0.2199114857512855}"""if (inductance, frequency, reactance).count(0) != 1:raise ValueError("One and only one argument must be 0")if inductance < 0:raise ValueError("Inductance cannot be negative")if frequency < 0:raise ValueError("Frequency cannot be negative")if reactance < 0:raise ValueError("Inductive reactance cannot be negative")if inductance == 0:return {"inductance": reactance / (2 * pi * frequency)}elif frequency == 0:return {"frequency": reactance / (2 * pi * inductance)}elif reactance == 0:return {"reactance": 2 * pi * frequency * inductance}else:raise ValueError("Exactly one argument must be 0")if __name__ == "__main__":import doctestdoctest.testmod()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型