每次我尝试转换它时,它只显示从 in. 到 mm 的转换。(又名第一个表达式)如果您能提供帮助,我将非常感激,因为我花了很长时间。
a = input('Original Amount:')
b = input('Original Unit: ')
c = input('What to convert to: ')
if b == 'in.' or 'in':
if c == 'mm.' or 'mm':
print(float(a) * float(25.4))
elif c == 'cm.' or 'cm':
print(float(a) * float(2.54))
elif c == 'ft.' or 'ft':
print(float(a) / float(12))
elif c == 'yd.' or 'yd':
print(float(a) / float(36))
elif c == 'mi.' or 'mi':
print(float(a) / float(63360))
elif c == 'km.' or 'km':
print(float(a) / float(8500.8))
elif c == 'm.' or 'm':
print(float(a) / float(39.37))
elif c == 'rod.' or 'rod':
print(float(a) / float(4.55))
elif b == 'ft.' or 'ft':
if c == 'in.' or 'in':
print(float(a) * float(12))
elif c == 'yd.' or 'yd':
print(float(a) / float(3))
elif c == 'mi.' or 'mi':
print(float(a) / float(5280))
elif c == 'rod.' or 'rod':
print(float(a) / float(16.5))
elif c == 'mm.' or 'mm':
print(float(a) * float(304.8))
elif c == 'cm.' or 'cm':
print(float(a) * float(30.48))
elif c == 'm.' or 'm':
print(float(a) / float(27.3))
elif c == 'km.' or 'km':
print(float(a) / float(3281))
elif b == 'yd.' or 'yd':
if c == 'in.' or 'in':
print(float(a) * float(36))
elif c == 'ft.' or 'ft':
print(float(a) * float(3))
elif c == 'mi.' or 'mi':
print(float(a) / float(1760))
elif c == 'rod.' or 'rod':
print(float(a) / float(5.5))
elif c == 'mm.' or 'mm':
print(float(a) * float(914.4))
elif c == 'cm.' or 'cm':
print(float(a) * float(91.44))
elif c == 'm.' or 'm':
print(float(a) * float(0.91))
elif c == 'km.' or 'km':
print(float(a) / float(1094))
elif b == 'mi.' or 'mi':
if c == 'in.' or 'in':
print(float(a) * float(63360))
elif c == 'ft.' or 'ft':
print(float(a) * float(5280))
elif c == 'yd.' or 'yd':
print(float(a) * float(1760))
elif c == 'rod.' or 'rod':
print(float(a) * float(320))
elif c == 'mm.' or 'mm':
print(float(a) * float(1609344))
elif c == 'cm.' or 'cm':
print(float(a) * float(160934.4))
elif c == 'm.' or 'm':
print(float(a) * float(1609.34))
elif c == 'km.' or 'km':
print(float(a) * float(1.61))
elif b == 'rod.' or 'rod':
if c == 'in.' or 'in':
print(float(a) * float(198))
elif c == 'ft.' or 'ft':
print(float(a) * float(16.5))
elif c == 'yd.' or 'yd':
print(float(a) * float(5.5))
elif c == 'mi.' or 'mi':
print(float(a) * float(320))
elif c == 'mm.' or 'mm':
print(float(a) * float(5029.2))
elif c == 'cm.' or 'cm':
print(float(a) * float(502.92))
elif c == 'm.' or 'm':
print(float(a) * float(5))
elif c == 'km.' or 'km':
print(float(a) * float(198.8))
elif b == 'mm.' or 'mm':
if c == 'in.' or 'in':
print(float(a) / float(25.4))
elif c == 'ft.' or 'ft':
print(float(a) / float(304.8))
elif c == 'yd.' or 'yd':
print(float(a) / float(914.4))
elif c == 'mi.' or 'mi':
print(float(a) / float(6.21))
elif c == 'rod.' or 'rod':
print(float(a) / float(5029))
elif c == 'cm.' or 'cm':
print(float(a) / float(10))
elif c == 'm.' or 'm':
print(float(a) / float(1000))
elif c == 'km.' or 'km':
print(float(a) / float(1000000))
elif b == 'cm.' or 'cm':
if c == 'in.' or 'in':
print(float(a) / 2.54)
elif c == 'ft.' or 'ft':
print(float(a) / float(30.48))
elif c == 'yd.' or 'yd':
print(float(a) / float(91.44))
elif c == 'mi.' or 'mi':
print(float(a) * float(6.21))
elif c == 'rod.' or 'rod':
print(float(a) * float(502.9))
elif c == 'mm.' or 'mm':
print(float(a) * float(10))
elif c == 'm.' or 'm':
print(float(a) / float(100))
elif c == 'km.' or 'km':
print(float(a) / float(100000))
elif b == 'm.' or 'm':
if c == 'in.' or 'in':
print(float(a) * float(39.37))
elif c == 'ft.' or 'ft':
print(float(a) * float(3.281))
elif c == 'yd.' or 'yd':
print(float(a) * float(1.094))
elif c == 'mi.' or 'mi':
print(float(a) / float(1609))
elif c == 'rod.' or 'rod':
print(float(a) / float(5.029))
elif c == 'mm.' or 'mm':
print(float(a) * float(1000))
elif c == 'cm.' or 'cm':
print(float(a) * float(100))
elif c == 'km.' or 'km':
print(float(a) / float(1000))
elif b == 'km.' or 'km':
if c == 'in.' or 'in':
print(float(a) * float(39370))
elif c == 'ft.' or 'ft':
print(float(a) * float(3281))
elif c == 'yd.' or 'yd':
print(float(a) * float(1094))
elif c == 'mi.' or 'mi':
print(float(a) / float(1.609))
elif c == 'rod.' or 'rod':
print(float(a) * float(198.8))
elif c == 'mm.' or 'mm':
print(float(a) * float(1000000))
elif c == 'cm.' or 'cm':
print(float(a) * float(100000))
elif c == 'm.' or 'm':
print(float(a) * float(1000))
elif b == 'oz.' or 'oz':
if c == 'lb.' or 'lb':
print(float(a) / float(16))
elif c == 'USton.' or 'USton':
print(float(a) / float(2000))
elif c == 'IMPton.' or 'IMPton':
print(float(a) / float(2240))
elif c == 'gram.' or 'gram':
print(float(a) * float(28.35))
elif c == 'Mgram.' or 'Mgram':
print(float(a) * float(28350))
elif c == 'kg.' or 'kg':
print(float(a) / float(2.205))
elif c == 'Mton.' or 'Mton':
print(float(a) / float(2205))
elif b == 'lb.' or 'lb':
if c == 'oz.' or 'oz':
print(float(a) * float(16))
elif c == 'USton.' or 'USton':
print(float(a) / float(2000))
elif c == 'IMPton.' or 'IMPton':
print(float(a) / float(2240))
elif c == 'gram.' or 'gram':
print(float(a) * float(453.6))
elif c == 'Mgram.' or 'Mgram':
print(float(a) * float(453600))
elif c == 'kg.' or 'kg':
print(float(a) / float(2.205))
elif c == 'Mton.' or 'Mton':
print(float(a) / float(2205))
elif b == 'USton.' or 'USton':
if c == 'oz.' or 'oz':
print(float(a) * float(32000))
elif c == 'lb.' or 'lb':
print(float(a) * float(2000))
elif c == 'IMPton.' or 'IMPton':
print(float(a) / float(1.12))
elif c == 'gram.' or 'gram':
print(float(a) * float(907200))
elif c == 'Mgram.' or 'Mgram':
print(float(a) * float(907200000))
elif c == 'kg.' or 'kg':
print(float(a) * float(907.2))
elif c == 'Mton.' or 'Mton':
print(float(a) / float(1.102))
elif b == 'IMPton.' or 'IMPton':
if c == 'oz.' or 'oz':
print(float(a) * float(35840))
elif c == 'lb.' or 'lb':
print(float(a) * float(2240))
elif c == 'USton.' or 'USton':
print(float(a) * float(1.12))
elif c == 'gram.' or 'gram':
print(float(a) * float(1.016e+6))
elif c == 'Mgram.' or 'Mgram':
print(float(a) * float(1.016e+9))
elif c == 'kg.' or 'kg':
print(float(a) * float(1016))
elif c == 'Mton.' or 'Mton':
print(float(a) * float(1.016))
elif b == 'gram.' or 'gram':
if c == 'oz.' or 'oz':
print(float(a) / float(28.35))
elif c == 'Mgram.' or 'Mgram':
print(float(a) * float(1000))
elif c == 'lb.' or 'lb':
print(float(a) / float(453.6))
elif c == 'USton.' or 'USton':
print(float(a) / float(907200))
elif c == 'IMPton.' or 'IMPton':
print(float(a) / float(1.016e+6))
elif c == 'kg.' or 'kg':
print(float(a) / float(1000))
elif c == 'Mton.' or 'Mton':
print(float(a) / float(1e+6))
elif b == 'kg.' or 'kg':
if c == 'oz.' or 'oz':
print(float(a) * float(35.274))
elif c == 'lb.' or 'lb':
print(float(a) * float( 2.205))
elif c == 'USton.' or 'USton':
print(float(a) / float(907.2))
elif c == 'IMPton.' or 'IMPton':
print(float(a) / float(1016))
elif c == 'gram.' or 'gram':
print(float(a) * float(1000))
elif c == 'Mgram.' or 'Mgram':
print(float(a) * float(1000000))
elif c == 'Mton.' or 'Mton':
print(float(a) / float(1000))
elif b == 'Mgram.' or 'Mgram':
if c == 'oz.' or 'oz':
print(float(a) / float(28350))
elif c == 'lb.' or 'lb':
print(float(a) / float(453600))
elif c == 'USton.' or 'USton':
print(float(a) / float(9.072e+8))
elif c == 'IMPton.' or 'IMPton':
print(float(a) / float(1.016e+9))
elif c == 'gram.' or 'gram':
print(float(a) * float(1000))
elif c == 'kg.' or 'kg':
print(float(a) * float(1e+6))
elif c == 'Mton.' or 'Mton':
print(float(a) * float(1e+9))
elif b == 'Mton.' or 'Mton':
if c == 'oz.' or 'oz':
print(float(a) * float(35270))
elif c == 'lb.' or 'lb':
print(float(a) * float(2205))
elif c == 'USton.' or 'USton':
print(float(a) * float(1.102))
elif c == 'IMPton.' or 'IMPton':
print(float(a) / float(1.016))
elif c == 'gram.' or 'gram':
print(float(a) * float(1e+6))
elif c == 'Mgram.' or 'Mgram':
print(float(a) * float(1e+9))
elif c == 'kg.' or 'kg':
print(float(a) * float(1000))
我期望该程序实际上能达到预期的效果,因为我是初学者,所以我无法发现问题或解决方案,所以请帮忙!
代码中的问题在于 if 语句中的条件。当你写下
b == 'in.' or 'in'
时,它并没有按照你的预期进行。它应该写成 b == 'in.' or b == 'in'.
您需要明确提及每个条件中的变量。
与所有条件语句相同