Possible Duplicate:
how can I force division to be floating point in Python?
如果这个问题已经被问过了,我很抱歉。在
timothy_lewis_three_pointers_attempted = 4
timothy_lewis_three_pointers_made = 2
print 'three pointers attempted: ' + str(timothy_lewis_three_pointers_attempted)
print 'three pointers made: ' + str(timothy_lewis_three_pointers_made)
print 'three point percentage: ' + str(timothy_lewis_three_point_percentage)
我的百分比是0。我怎么才能让它说。5?我知道如果我输入4.0和2.0的数字,我会得到想要的结果,但是有没有其他方法可以做到呢?在
你还有一个选择(尽管我不推荐)是使用
然后呢
^{pr2}$这是基于PEP 238。在
你在做整数除法。至少使其中一个成为浮点值
您还可以通过使用新的字符串格式方法获得更好的百分比输出。在
^{pr2}$将其中一个设为
float
:相关问题 更多 >
编程相关推荐