Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何修复TypeError:无法解压缩不可编辑的非类型对象_Python - Fatal编程技术网

Python 如何修复TypeError:无法解压缩不可编辑的非类型对象

Python 如何修复TypeError:无法解压缩不可编辑的非类型对象,python,Python,我一次又一次地犯下这个错误,即使有一些小的修正,它也总是会出错。我被告知将包含数字的变量更改为字母ex.Player1->playeron。但这仍然不能解决打字错误 我已经包含了完整的回溯,以进一步帮助发现另一个用户请求的代码问题 What is your username? User1 What is your password? password Welcome, User1 you have been successfully logged in. What is your usernam

我一次又一次地犯下这个错误,即使有一些小的修正,它也总是会出错。我被告知将包含数字的变量更改为字母ex.Player1->playeron。但这仍然不能解决打字错误

我已经包含了完整的回溯,以进一步帮助发现另一个用户请求的代码问题

What is your username? User1
What is your password? password
Welcome, User1 you have been successfully logged in.
What is your username? User2
What is your password? password
Welcome, User2 you have been successfully logged in.
After this round User1 you now have: 10 Points
After this round User2 you now have: 9 Points
After this round User1 you now have: 13 Points
After this round User2 you now have: 19 Points
After this round User1 you now have: 16 Points
After this round User2 you now have: 26 Points
After this round User1 you now have: 22 Points
After this round User2 you now have: 37 Points
Traceback (most recent call last):
  File "C:\Users\corn\Desktop\nea\cs nea.py", line 81, in <module>
    main()
  File "C:\Users\corn\Desktop\nea\cs nea.py", line 69, in main
    (playerOne, playerOne_win), (playerTwo, playerTwo_win) = game(userOne, userTwo);
TypeError: cannot unpack non-iterable NoneType object

调用game(userOne,userTwo)的game()函数没有返回任何内容,返回NoneType错误:

(playerOne, playerOne_win), (playerTwo, playerTwo_win) = game(userOne, userTwo);
只需在函数末尾添加一行:
返回(playerOne,playerOne\u-win),(playerTwo,playerTwo\u-win)
替换这些名称以获得该函数中正确的变量。

并将帖子限制为单个问题。你需要一个“类型错误:无法解包不可编辑的非类型对象”:你没有从
def game(…
)返回显式值,因此
NoneType
,这是返回的默认值。我插入了:return(playerne,playerne\u-win),(playerTwo,playerTwo\u-win)在主函数的末尾,它仍然输出相同的错误。你是否替换了函数中相应变量的playerOne和playerOne_win?我想如果userOne赢了,你应该返回(userOne,True),(userTwo,False)。你能再澄清一下游戏的内容吗()函数正在尝试返回?我对Playeron和UserOnePlayerone_points之间的区别感到困惑。playerOne_points在main中不在作用域内,因此您将无法在print()中打印它。如果您不在字符串的开头添加一个f,则无论如何都无法打印它,如
print(f'blablabla{playerOne_points})
。关于这方面的更多信息:更多地查看您的代码,我认为您希望
返回(玩家积分,玩家赢),(玩家赢两个积分,玩家赢两个)
以便积分进入主范围,您可以打印它们。您只需根据游戏中的赢家定义赢变量()。你没有在main()中再次使用playerOne或playerTwo,因此我假设它们与userOne和userTwo相同。我刚刚意识到你说你试图在main()的末尾返回(playerOne,playerOne,playerTwo),我是说你必须从game()中返回它们。
(playerOne, playerOne_win), (playerTwo, playerTwo_win) = game(userOne, userTwo);