[英]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.