if act == "block" and enemy_decision != 2:
percentage_blocked = (enemy_attack - block)/(enemy_attack) * 100
print("You have blocked %s percent of the enemy's attack." % percentage_blocked)
从这里我得到的数字如82.113124523242323。我怎样才能把这个比例提高到第10位呢82.1。在Python中舍入百分比
你可以使用:math.ceil 在这里看到:http://stackoverflow.com/questions/4518641/how-to-round-off-a-floating-number-in-python – nvg58
当心:一浮点数不能精确地表示值82.1。最接近的是82.099999999999994315658113919198513031005859375。不过,它在打印时仍然会显示为82.1。 – Kevin