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