简体   繁体   English

如何计算两个指数数之间的差

[英]how to calculate the difference between two exponential number

I want to use python to calculate the difference between two exponential number我想用python来计算两个指数数之间的差

a = 4,592e+9
b = 7,892e+9
c = b - a
print ('c = ',c)

I get the following error message:我收到以下错误消息:

TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'

Simply replace the , with .只需将,替换为.

a = 4.592e+9
b = 7.892e+9
c = b - a
print ('c = ',c)

Replacing , with .替换 will sort out your issue as you are trying to perform mathematical operations on a float value.当您尝试对浮点值执行数学运算时,将解决您的问题。

Working Code:工作代码:

a = 4.592e+9
b = 7.892e+9
c = b - a
print ('c = ',c)

You get that error because a and b are both tuples not real exponential numbers .你得到这个错误是因为 a 和 b 都是元组而不是真正的指数数 If you print the value of a you'd get (4, 592000000000.0) .如果你打印 a 的值,你会得到(4, 592000000000.0) The problem is with the declaration of a and b, just change the , with .问题在于 a 和 b 的声明,只需将,更改为. . . So:所以:

a = 4.592e+9
b = 7.892e+9
c = b - a 
print ('c = ',c)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM