【发布时间】:2019-10-20 14:51:01
【问题描述】:
我正在为学校做文字游戏练习,我们必须为它制作四个不同的功能。我已经完成了健康点系统,现在我想打印玩家使用了多少百分比。
这是我的 hp 系统:
def hela(player_health, hit):
return player_health - hit
player_health_points = 15
dog_hit_value = 4
pistol_hit_value = 15
brasnuckles_hit_value = 3
punch_hit_value = 1
kick_hit_value = 2
player_health_points = hela(player_health_points, dog_hit_value,)
player_health_points = hela(player_health_points, brasnuckles_hit_value)
print('You have ' + str(player_health_points) + ' HP left!')*
这就是我现在所做的,并因此失去了休息的大脑:
def hp_left_percentage(x,y):
vastaus = x - y
return vastaus
health = 16
tulos = hp_left_percentage(health,player_health_points)
print(tulos)
问题:
为什么我必须为 def hp_left_percentage health 添加一个才能显示正确的值?
现在 def hp_left_percentage 显示玩家有多少生命值,以及数值。我如何获得功能打印百分比?
希望你能明白我的意思:)
【问题讨论】:
标签: python function percentage