プレイヤーのHP、最大HP、および回復量を取得して新しいHPを返す関数を作成しようとしていますが、最大HPよりも高い新しいHPを返しません。どこかで計算を間違えたに違いないが、どこか分からない。私の最初の試み:
def heal(hp,max_hp,heal):
if hp > heal:
return (max_hp + heal)
else:
overflow = heal-max_hp
new_hp = hp - overflow
return (new_hp)
hp = heal(10,30,20)
print hp #prints 20, should print 30
hp = heal(10,30,10)
print hp #prints 30, should print 20
hp = heal(10,20,30)
print hp #prints 0, should print 20.
私の2回目の試み:
def heal(hp,max_hp,heal):
if hp > heal:
return (max_hp + heal)
else:
overflow = max_hp - heal
new_hp = hp - overflow
return (new_hp)
hp = heal(10,30,20)
print hp #prints 0, should print 30
hp = heal(10,30,10)
print hp #prints -10, should print 20
hp = heal(10,20,30)
print hp #prints 20, should print 20.