[英]my function isn't returning anything in 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)
每次我尝试使用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
我正在尝试做的是获取要显示在打印语句中的出价,以及用于对其他变量进行数学运算的出价。
将所有对bidf()
调用替换为return bidf()
。
当您在代码中调用bidf()
时,您需要存储返回值。 因此,请执行以下操作:
if g=="y":
bid = bidf()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.