繁体   English   中英

我不断收到此错误,我不确定我做错了什么

[英]I keep on getting this error and im not sure what i did wrong

这是我的代码:

def game_changer(games_list, game):
    if game == "":
        game.pop()
        return game + " popped from the list"
    elif game != "":
        if game in games_list:
            game.remove()
            return "1 instance of " + game + " is removed from the list"
        else:
            games_list.append(game)
            return game + "got apppended to the list"

boardg_list = ["Monopoly", "Sequence", "Connect Four"]

while boardg_list != "":
    print("Here is the list of games:", boardg_list)
    boardg = input("Enter the name of a board game or quit to quit: ")
    if boardg.lower() == "quit":
        print("Goodbye!")
        break
    else:
        result = game_changer(boardg, boardg_list)

这是我得到的错误:

Traceback (most recent call last):
  File "C:\Users\prooney\Documents\dev\sodump\leftoperand9.py", line 22, in <module>
    result = game_changer(boardg, boardg_list)
  File "C:\Users\prooney\Documents\dev\sodump\leftoperand9.py", line 6, in game_changer
    if game in games_list:
TypeError: 'in <string>' requires string as left operand, not list

我不确定我做错了什么以及为什么会出现此错误。

如错误消息所述,尝试从以下位置切换参数:

result = game_changer(boardg, boardg_list)

至:

result = game_changer(boardg_list, boardg)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM