0

コンピュータサイエンスの授業で働いているゲームの関数定義を作成しました。

 def bidf(bid): #this card is going to repeat until they give a valid bid
     bid=float(input("What is your bid? "))
     if bid>pot:
         print("Invalid bid: You can't bid more than what is in the pot")
         bidf()
     elif bid>value:
         print("Invalid bid: You don't have that much")
         bidf()
     elif bid<0:
         print("You can not bid negative money")
         bidf()
     else:
         return float(bid)

入札変数を使おうとすると機能しませんたとえば、このコードは常にクラッシュする場所です

if g=="y":
      bidf()
      if card(insidecard[0])==card(outsidecard[0]):
           z=input("Will the next card be higher or lower than the pair?(h/l): ")
           if card(insidecard[0])==14 and card(hand[0])==14:
                print("You quadruple your bid and lose $",bid)
                bid=bid*4
                value=value-bid
                pot=pot+bid

私がやろうとしているのは、印刷ステートメントに表示される入札と、他の変数の計算に使用される入札です。

4

2 に答える 2

3

bidf()へのすべての呼び出しをに置き換えますreturn bidf()

于 2013-03-04T02:48:07.173 に答える
0

コードを呼び出すときはbidf()、戻り値を格納する必要があります。したがって、次のようなことを行います。

if g=="y":
    bid = bidf()
于 2013-03-04T02:58:22.947 に答える