制作轮盘游戏,不断出错 python
Making a roulette game, keep getting error in python
我是 python 的新手,很抱歉,如果这有点基础。
我着手制作轮盘游戏以提高我的编程技能,但遇到了一个非常奇怪的错误。起初,当我想在滚动结束时打印玩家的余额并且检查结果后,它会打印出包含所有红色数字的数组。我查看了定义 balance
变量的代码,但没有任何东西看起来可能会影响它。
我出于某种原因认为将 balance
定义为 int(100)
而不是 100
可能会修复它,但我却得到了这个错误:TypeError: checkresults() missing 1 required positional argument: 'bet'
我删除了 int
在 balance
它仍然存在。对于那些想知道的人,我让 checkresults
使用 bet
,甚至尝试移动它在使用的变量列表中的位置,但仍然没有修复。 balance = checkresults(bet, bet_choice, number, balance, red, black, green, first, second, third)
如您所见,这是它使用的第一个变量。 checkresults
的完整代码在这里:
def checkresults(self, bet_choice, number, balance, red, black, green, first, second, third, bet):
if bet_choice == "number":
if bet == number:
balance = balance + (bet_amount*14)
print("You Won!")
else:
print("You Lost")
elif bet_choice == "colour":
if bet == "red":
if number in red:
balance = balance + (bet_amount*2)
print("You Won!")
else:
print("You Lost")
elif bet == "black":
if number in black:
balance = balance + (bet_amount*2)
print("You Won!")
else:
print("You Lost")
else:
if number in green:
balance = balance + (bet_amount*14)
print("You Won!")
else:
print("You Lost")
elif bet_choice == "third":
if bet == "1st":
if number in first:
balance = balance + (bet_amount*3)
print("You Won!")
else:
print("You Lost")
elif bet == "2nd":
if number in second:
balance = balance + (bet_amount*3)
print("You Won!")
else:
print("You Lost")
elif bet == "3rd":
if number in third:
balance = balance + (bet_amount*3)
print("You Won!")
else:
print("You Lost")
return balance
下注金额由此决定:
def choosebet():
bet_choice = input("Would you like to bet on a number, colour, or a third? ")
if bet_choice == "number":
bet = int(input("Which number would you like to bet on? "))
elif bet_choice == "colour":
bet = input("Which colour would you like to bet on?")
else:
bet = input("Which third would you like to bet on?")
return bet, bet_choice
我在 checkresults
代码的定义部分有 self
,这是由于之前的错误。我删除了 self
和 1:它修复了新错误和 2:旧错误没有回来。
checkresults
定义有 11 个参数——看起来第一个参数应该是 class 的一个实例,checkresults
在 中定义 - 当你直接调用方法而不引用实例时它认为你没有传递第十一个参数。
我也在做同样的事情。我大约在两个半月前开始 python,过去一个月一直在研究轮盘游戏。
这没有回答问题,但我在开始时遇到了类似的问题。如果您的意图是构建整个游戏,那么您所走的道路是不可持续的。将有太多的 elif 语句,你会想要撕掉你的头发(就像我一样)。
我最后做的是将所有 "constants" 放入字典。我所说的常量是指每次下注中的数字(红色与黑色、奇数与偶数等)、轮盘上的数字以及每次下注的支出。
从那里您可以使用字典方法在投注字典中查找中奖号码(即这是红色还是黑色号码),然后将其与下注字典进行比较,如果匹配,查看投注的赔率。
祝你好运!
我是 python 的新手,很抱歉,如果这有点基础。
我着手制作轮盘游戏以提高我的编程技能,但遇到了一个非常奇怪的错误。起初,当我想在滚动结束时打印玩家的余额并且检查结果后,它会打印出包含所有红色数字的数组。我查看了定义 balance
变量的代码,但没有任何东西看起来可能会影响它。
我出于某种原因认为将 balance
定义为 int(100)
而不是 100
可能会修复它,但我却得到了这个错误:TypeError: checkresults() missing 1 required positional argument: 'bet'
我删除了 int
在 balance
它仍然存在。对于那些想知道的人,我让 checkresults
使用 bet
,甚至尝试移动它在使用的变量列表中的位置,但仍然没有修复。 balance = checkresults(bet, bet_choice, number, balance, red, black, green, first, second, third)
如您所见,这是它使用的第一个变量。 checkresults
的完整代码在这里:
def checkresults(self, bet_choice, number, balance, red, black, green, first, second, third, bet):
if bet_choice == "number":
if bet == number:
balance = balance + (bet_amount*14)
print("You Won!")
else:
print("You Lost")
elif bet_choice == "colour":
if bet == "red":
if number in red:
balance = balance + (bet_amount*2)
print("You Won!")
else:
print("You Lost")
elif bet == "black":
if number in black:
balance = balance + (bet_amount*2)
print("You Won!")
else:
print("You Lost")
else:
if number in green:
balance = balance + (bet_amount*14)
print("You Won!")
else:
print("You Lost")
elif bet_choice == "third":
if bet == "1st":
if number in first:
balance = balance + (bet_amount*3)
print("You Won!")
else:
print("You Lost")
elif bet == "2nd":
if number in second:
balance = balance + (bet_amount*3)
print("You Won!")
else:
print("You Lost")
elif bet == "3rd":
if number in third:
balance = balance + (bet_amount*3)
print("You Won!")
else:
print("You Lost")
return balance
下注金额由此决定:
def choosebet():
bet_choice = input("Would you like to bet on a number, colour, or a third? ")
if bet_choice == "number":
bet = int(input("Which number would you like to bet on? "))
elif bet_choice == "colour":
bet = input("Which colour would you like to bet on?")
else:
bet = input("Which third would you like to bet on?")
return bet, bet_choice
我在 checkresults
代码的定义部分有 self
,这是由于之前的错误。我删除了 self
和 1:它修复了新错误和 2:旧错误没有回来。
checkresults
定义有 11 个参数——看起来第一个参数应该是 class 的一个实例,checkresults
在 中定义 - 当你直接调用方法而不引用实例时它认为你没有传递第十一个参数。
我也在做同样的事情。我大约在两个半月前开始 python,过去一个月一直在研究轮盘游戏。
这没有回答问题,但我在开始时遇到了类似的问题。如果您的意图是构建整个游戏,那么您所走的道路是不可持续的。将有太多的 elif 语句,你会想要撕掉你的头发(就像我一样)。
我最后做的是将所有 "constants" 放入字典。我所说的常量是指每次下注中的数字(红色与黑色、奇数与偶数等)、轮盘上的数字以及每次下注的支出。
从那里您可以使用字典方法在投注字典中查找中奖号码(即这是红色还是黑色号码),然后将其与下注字典进行比较,如果匹配,查看投注的赔率。
祝你好运!