python - 制作轮盘游戏,python中不断报错
问题描述
我对python相当陌生,如果这有点基本,很抱歉。我已经着手制作轮盘游戏来提高我的编程技能,并且遇到了一个非常奇怪的错误。起初,当我想在滚动结束时打印玩家的余额并且检查结果后,它会打印出包含所有红色数字的数组。我查看了定义balance
变量的代码,但没有任何东西看起来可能会影响它。出于某种原因,我认为定义balance
asint(100)
而不是100
可能会修复它,但我却得到了这个错误:TypeError: checkresults() missing 1 required positional argument: 'bet'
我删除了int
inbalance
并且它仍然存在。对于那些想知道的人,我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
解决方案
我self
在代码的定义部分中checkresults
,来自以前的错误。我删除self
了 1:它修复了新错误和 2:旧错误没有回来。
推荐阅读
- java - 我想在spring boot中动态地从db中获取数据
- javascript - 从离线 html 文件中的文件夹加载本地图像?
- r - R dplyr:按组汇总数据时处理NA值和空/缺失行
- ios - Swift CoreML - 如何转置 MLMMultiArray?
- google-cloud-platform - 在公共 Cloud Run 服务上使用 Pub/Sub
- node.js - 如何通过 imgur 包上传图片
- php - 显示和保存来自购物车和结帐的自定义输入的自定义项目数据
- javascript - 显示先前选择的下拉选择
- ios - NSLayout 约束不适用于自定义视图
- firewall - 添加自动防火墙规则 pfsense