【发布时间】:2020-11-23 20:39:47
【问题描述】:
我的代码尝试将数字转换为例如 X 米 Y 厘米和 Z 毫米。我的代码对于没有 out 的数字正常工作5782 之类的任何零,但是当涉及到零的数字时,它将无法正常工作
这是我的代码:
a = 2200
b = a / 1000
print(float(b))
b = str(float(b)).split(".")
first = b[0]
print(first,b[1])
c = (float(b[1])/10)
print(c)
c = str(c).split(".")
print(c)
second = (c[0])
third = (c[1])
print("%s Meter %s centimeter %s milimeter"%(first,second,third))
结果必须像 2 米 20 厘米 0 毫米,但它给了我 2 米 0 厘米 2 毫米
我该如何解决这些问题?
【问题讨论】:
标签: python type-conversion typeconverter