1

次のコードは機能しません:

try:
    get_current_player(request).cash >= bid # does the player have enough cash for this bid ?
except ValueError:
    messages.error(request, "You don't have the necessary funds to place a bid of <span class='cash'>%d</span> !" % (bid))
messages.success(request, "You placed a bid of %d !" % (bid))

入札額が現在のプレーヤーの現金よりも高い場合、エラー メッセージの代わりに成功メッセージが出力されます。

ただし、次のコードは機能し、値が正しいことを示します。

if get_current_player(request).cash >= bid : # does the player have enough cash for this bid ?
    messages.success(request, "You placed a bid of %d !" % (bid))
else :
    messages.error(request, "You don't have the necessary funds to place a bid of <span class='cash'>%d</span> !" % (bid))

try/except を間違って使用していますか?

4

3 に答える 3