首页 > 解决方案 > 制作轮盘游戏,python中不断报错

问题描述

我对python相当陌生,如果这有点基本,很抱歉。我已经着手制作轮盘游戏来提高我的编程技能,并且遇到了一个非常奇怪的错误。起初,当我想在滚动结束时打印玩家的余额并且检查结果后,它会打印出包含所有红色数字的数组。我查看了定义balance变量的代码,但没有任何东西看起来可能会影响它。出于某种原因,我认为定义balanceasint(100)而不是100可能会修复它,但我却得到了这个错误:TypeError: checkresults() missing 1 required positional argument: 'bet'我删除了intinbalance并且它仍然存在。对于那些想知道的人,我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

标签: pythonpython-3.7

解决方案


self在代码的定义部分中checkresults,来自以前的错误。我删除self了 1:它修复了新错误和 2:旧错误没有回来。


推荐阅读