我的代码抛出了一个我无法弄清楚的TypeError

时间:2017-05-09 15:59:39

标签: python-3.x

所以,我一直在研究一个幸运之轮的python实现,每次我测试我的代码它工作正常但经过一段时间的测试后它会抛出一个错误。这是代码:

from random import choice
def spin_the_wheel():
    wheel = ["BANKRUPT", 650, "FREE PLAY", 700, "LOSE A TURN", 800, 500, 650, 500, 900, "BANKRUPT", 2500, 500, 900, 700, 600, 800, 500, 700, 500, 600, 550, 500, 900]
    return choice(wheel)
def make_text_blank(text):
    l = list(text)
    for i in range(len(text)):
    if text[i].isalpha():
        l[i] = "_"
    return "".join(l)
def fill_in_the_blanks(blank_text, text, letter):
    bt = list(blank_text)
    t = list(text)
    for i in range(len(t)):
        if t[i] == letter:
            bt[i] = letter
    return "".join(bt)
def remove_duplicates(lst):
    result = []
    for i in lst:
        if i not in result:
            result.append(i)
    return result
def vowels_in_text(text):
    result = []
    vowels = ['A', 'E', 'I', 'O', 'U']
    for i in range(len(text)):
        if text[i] in vowels:
            result.append(text[i])
    result = remove_duplicates(result)
    return result
def wheel_of_fortune():
    print("The category for this puzzle is game show")
    text = "WHEEL OF FORTUNE"
    blank_text = make_text_blank(text)
    print(blank_text)
    print("Player 1 is up first")
    while blank_text != text:
        letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
        vit = vowels_in_text(text)
        player1(text, blank_text, letters, vit, 0, 0, 0)
def player1(text, blank_text, letters, vit, player1amount, player2amount, player3amount):
    prize = spin_the_wheel()
    print("The wheel landed on " + str(prize))
    if prize == "BANKRUPT":
        player1amount = 0
        print("We go to player 2 now")
        player2(text, blank_text, vit, 0, player2amount, player3amount)
    elif prize == "LOSE A TURN":
        print("We go to player 2 now")
        player2(text, blank_text, vit, player1amount, player2amount, player3amount)
    elif prize == "FREE PLAY":
        letter = input("Guess a letter: ").upper()
        if letter not in text:
            letters.remove(letter)
            print("There are no " + letter + "'s")
            print("We go to player 2 now")
            player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
        elif letter not in letters:
            print("That letter's already been called")
            print("We go to player 2 now")
            player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
        else:
            letters.remove(letter)
            if text.count(letter) == 1:
               print("There is 1 " + letter)
               blank_text = fill_in_the_blanks(blank_text, text, letter)
               print(blank_text)
            player1amount += 500
            choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
            def do(blank_text, choice):
                if choice == "spin the wheel":
                    print("OK, spin the wheel")
                    player1(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                elif choice == "buy a vowel":
                    vowel = input("OK, buy a vowel: ").upper()
                    if vowel not in text:
                        letters.remove(vowel)
                        print("There are no " + vowel + "'s")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                    elif vowel not in letters:
                        print("That vowel's already been called")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                    else:
                        letters.remove(vowel)
                        vit.remove(vowel)
                        if text.count(vowel) == 1:
                            print("There is 1 " + vowel)
                            blank_text = fill_in_the_blanks(blank_text, text, vowel)
                            print(blank_text)
                            if vit == []:
                                print("No more vowels")
                                choice = input("Would you like to spin the wheel or solve the puzzle?: ")
                                do(blank_text, choice)
                            else:
                                choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
                                do(blank_text, choice)
                        else:
                            n = text.count(vowel)
                            print("There are " + str(n) + " " + vowel + "'s")
                            blank_text = fill_in_the_blanks(blank_text, text, vowel)
                            print(blank_text)
                            if vit == []:
                                print("No more vowels")
                                choice = input("Would you like to spin the wheel or solve the puzzle?: ")
                                do(blank_text, choice)
                            else:
                                choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
                                do(blank_text, choice)
                elif choice == "solve the puzzle":
                    solution = input("OK, solve the puzzle: ").upper()
                    if solution != text:
                        print("That's not right")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                    else:
                        print("That's right")
                        print(text)
                        print("Player 1 amount: $" + str(player1amount))
                        print("Player 2 amount: $" + str(player2amount))
                        print("Player 3 amount: $" + str(player3amount))
            do(blank_text, choice)
        else:
            n = text.count(letter)
            print("There are " + str(n) + " " + letter)
            blank_text = fill_in_the_blanks(blank_text, text, letter)
            print(blank_text)
            p = 500 * n
            player1amount += p
            choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
            def do(blank_text, choice):
                if choice == "spin the wheel":
                    print("OK, spin the wheel")
                    player1(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                elif choice == "buy a vowel":
                    vowel = input("OK, buy a vowel: ").upper()
                    if vowel not in text:
                        letters.remove(vowel)
                        print("There are no " + vowel + "'s")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                    elif vowel not in letters:
                        print("That vowel's already been called")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                    else:
                        letters.remove(vowel)
                        vit.remove(vowel)
                        if text.count(vowel) == 1:
                            print("There is 1 " + vowel)
                            blank_text = fill_in_the_blanks(blank_text, text, vowel)
                            print(blank_text)
                            if vit == []:
                                print("No more vowels")
                                choice = input("Would you like to spin the wheel or solve the puzzle?: ")
                                do(blank_text, choice)
                            else:
                                choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
                                do(blank_text, choice)
                        else:
                            n = text.count(vowel)
                            print("There are " + str(n) + " " + vowel + "'s")
                            blank_text = fill_in_the_blanks(blank_text, text, vowel)
                            print(blank_text)
                            if vit == []:
                                print("No more vowels")
                                choice = input("Would you like to spin the wheel or solve the puzzle?: ")
                                do(blank_text, choice)
                            else:
                                choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
                                do(blank_text, choice)
                elif choice == "solve the puzzle":
                    solution = input("OK, solve the puzzle: ").upper()
                    if solution != text:
                        print("That's not right")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                    else:
                        print("That's right")
                        print(text)
                        print("Player 1 amount: $" + str(player1amount))
                        print("Player 2 amount: $" + str(player2amount))
                        print("Player 3 amount: $" + str(player3amount))
            do(blank_text, choice)
    else:
        letter = input("Guess a letter: ").upper()
        if letter not in text:
            letters.remove(letter)
            print("There are no " + letter + "'s")
            print("We go to player 2 now")
            player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
        elif letter not in letters:
        print("That letter's already been called")
        print("We go to player 2 now")
        player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
    else:
        letters.remove(letter)
        if text.count(letter) == 1:
            print("There is 1 " + letter)
            blank_text = fill_in_the_blanks(blank_text, text, letter)
            print(blank_text)
            player1amount += prize
            choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
            def do(blank_text, choice, player1amount):
                if choice == "spin the wheel":
                    print("OK, spin the wheel")
                    player1(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                elif choice == "buy a vowel":
                    vowel = input("OK, buy a vowel: ").upper()
                    if vowel not in text:
                        letters.remove(vowel)
                        print("There are no " + vowel + "'s")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                    elif vowel not in letters:
                        print("That vowel's already been called")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                    else:
                        letters.remove(vowel)
                        vit.remove(vowel)
                        if text.count(vowel) == 1:
                            print("There is 1 " + vowel)
                            player1amount -= 250
                            blank_text = fill_in_the_blanks(blank_text, text, vowel)
                            print(blank_text)
                            if vit == []:
                                print("No more vowels")
                                choice = input("Would you like to spin the wheel or solve the puzzle?: ")
                                do(blank_text, choice, player1amount)
                            else:
                                choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
                                do(blank_text, choice, player1amount)
                        else:
                            n = text.count(vowel)
                            print("There are " + str(n) + " " + vowel + "'s")
                            blank_text = fill_in_the_blanks(blank_text, text, vowel)
                            print(blank_text)
                            d = 250 * n
                            player1amount -= d
                            if vit == []:
                                print("No more vowels")
                                choice = input("Would you like to spin the wheel or solve the puzzle?: ")
                                do(blank_text, choice, player1amount)
                            else:
                                choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
                                do(blank_text, choice, player1amount)
                elif choice == "solve the puzzle":
                    solution = input("OK, solve the puzzle: ").upper()
                    if solution != text:
                        print("That's not right")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
                    else:
                        print("That's right")
                        print(text)
                        print("Player 1 amount: $" + str(player1amount))
                        print("Player 2 amount: $" + str(player2amount))
                        print("Player 3 amount: $" + str(player3amount))
            do(blank_text, choice, player1amount)
        else:
            n = text.count(letter)
            print("There are " + str(n) + " " + letter + "'s")
            blank_text = fill_in_the_blanks(blank_text, text, letter)
            print(blank_text)
            p = prize * n
            player1amount += p
            if vit == []:
                choice = input("Would you like to spin the spin the wheel or solve the puzzle?: ")
            else:
                choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
            def do(blank_text, choice, player1amount):
                if choice == "spin the wheel":
                    print("OK, spin the wheel")
                    player1(text, blank_text, letters, player1amount, player2amount, player3amount)
                elif choice == "buy a vowel":
                    vowel = input("OK, buy a vowel: ").upper()
                    if vowel not in text:
                        letters.remove(vowel)
                        print("There are no " + vowel + "'s")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, player1amount, player2amount, player3amount)
                    elif vowel not in letters:
                        print("That vowel's already been called")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, player1amount, player2amount, player3amount)
                    else:
                        letters.remove(vowel)
                        vit.remove(vowel)
                        if text.count(vowel) == 1:
                            print("There is 1 " + vowel)
                            blank_text = fill_in_the_blanks(blank_text, text, vowel)
                            print(blank_text)
                            player1amount -= 250
                            if vit == []:
                                print("No more vowels")
                                choice = input("Would you like to spin the wheel or solve the puzzle?: ")
                                do(blank_text, choice, player1amount)
                            else:
                                choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
                                do(blank_text, choice, player1amount)
                        else:
                            n = text.count(vowel)
                            print("There are " + str(n) + " " + vowel + "'s")
                            blank_text = fill_in_the_blanks(blank_text, text, vowel)
                            print(blank_text)
                            d = 250 * n
                            player1amount -= 250
                            if vit == []:
                                print("No more vowels")
                                choice = input("Would you like to spin the wheel or solve the puzzle?: ")
                                do(blank_text, choice, player1amount)
                            else:
                                choice = input("Would you like to spin the wheel, buy a vowel, or solve the puzzle?: ")
                                do(blank_text, choice)
                elif choice == "solve the puzzle":
                    solution = input("OK, solve the puzzle: ").upper()
                    if solution != text:
                        print("That's not right")
                        print("We go to player 2 now")
                        player2(text, blank_text, letters, player1amount, player2amount, player3amount)
                    else:
                        print("That's right")
                        print(text)
                        print("Player 1 amount: $" + str(player1amount))
                        print("Player 2 amount: $" + str(player2amount))
                        print("Player 3 amount: $" + str(player3amount))
            do(blank_text, choice, player1amount)

这是错误:

    Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    wheel_of_fortune()
  File "C:\Users\Harry\Documents\randompythonprograms\wheeloffortune.py", line 41, in wheel_of_fortune
    player1(text, blank_text, letters, vit, 0, 0, 0)
  File "C:\Users\Harry\Documents\randompythonprograms\wheeloffortune.py", line 262, in player1
    do(blank_text, choice, player1amount)
  File "C:\Users\Harry\Documents\randompythonprograms\wheeloffortune.py", line 209, in do
    player1(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
  File "C:\Users\Harry\Documents\randompythonprograms\wheeloffortune.py", line 124, in player1
    do(blank_text, choice)
  File "C:\Users\Harry\Documents\randompythonprograms\wheeloffortune.py", line 74, in do
    player1(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
  File "C:\Users\Harry\Documents\randompythonprograms\wheeloffortune.py", line 262, in player1
    do(blank_text, choice, player1amount)
  File "C:\Users\Harry\Documents\randompythonprograms\wheeloffortune.py", line 209, in do
    player1(text, blank_text, letters, vit, player1amount, player2amount, player3amount)
  File "C:\Users\Harry\Documents\randompythonprograms\wheeloffortune.py", line 330, in player1
    do(blank_text, choice, player1amount)
  File "C:\Users\Harry\Documents\randompythonprograms\wheeloffortune.py", line 277, in do
    player1(text, blank_text, letters, player1amount, player2amount, player3amount)
 TypeError: player1() missing 1 required positional argument: 'player3amount'

每当我收到此错误时,我都会查看代码而我看不到任何导致此错误的内容,那么有人可以帮助我吗?我将不胜感激任何帮助。

2 个答案:

答案 0 :(得分:0)

你的职能定义是

def player1(text, blank_text, letters, vit, player1amount, player2amount, player3amount):

你正在调用

player1(text, blank_text, letters, player1amount, player2amount, player3amount)

它需要7个参数,你没有提供vit的值因此错误。

答案 1 :(得分:0)

你的职能定义是

def player1(text,blank_text,letters,vit,player1amount,player2amount,player3amount):

,您正在调用

player1(text,blank_text,letters,player1amount,player2amount,player3amount)

它需要7个参数,你没有提供值6因此错误。

<强>解决方案

def player1(text,blank_text,letters,vit,player1amount,player2amount,player3amount):