2013-03-04 123 views
0

我做了一个我在计算机科学课工作的游戏的函数定义。我的功能是没有返回任何东西在python

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 

我所试图做的是取得竞标露面在打印声明中,以及用于对其他变量进行数学运算的出价。

回答

0

当您在代码中调用bidf()时,您需要存储返回值。所以做类似的事情:

if g=="y": 
    bid = bidf() 
+0

感谢您的快速反应,我得到它的工作:D – user2130136 2013-03-04 03:06:45

3

return bidf()替换您的所有电话bidf()

+0

谢谢,这有帮助。现在我不知道我在想什么,我看着它。 – user2130136 2013-03-04 03:07:47