# -*- coding:utf-8 -*-
# @Time : 2018/6/14 9:30
# @File : resistance.py
"""
计算串联和并联的电阻
"""
def resistance(ar1, ar2):
assert ar1 > 0 and ar2 > 0, u'除非超导体,其他电阻必须大于0'
if isinstance(ar1, (int, float)) and isinstance(ar2, (int, float)):
cr = ar1 + ar2
br = round(ar1*ar2*1.0/(ar1+ar2), 2)
return u'串联后电阻:{0}\n并联后电阻{1}'.format(cr, br)
else:
return u'Error'
if __name__ == '__main__':
r1, r2 = map(eval, input(u"请输入2个电阻值('1','2'):"))
print resistance(r1, r2)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)