<p>我正在开发一个函数,它接受用户输入的四个人的名字,并将他们附加到一个列表中。但是通过下面的代码,我得到了这个用户错误。然而,当我声明一个全局变量时,我得到了一个无效的语法错误。如何修复代码?你知道吗</p>
<pre><code>Traceback (most recent call last):
File "mash.py", line 16, in <module>
print spouse()
File "mash.py", line 13, in spouse
significant_other = signficant_other.append(new_spouse)
NameError: global name 'signficant_other' is not defined
</code></pre>
<p>这是密码。你知道吗</p>
<pre><code>import random
# import random module
def spouse():
# defined function
significant_other =[]
#empty list
for x in range(4):
# for loop for an iteration of four
new_spouse = str(raw_input("Type a person you would like to spend your life with."))
# new spouse input
significant_other = signficant_other.append(new_spouse)
#significant other gets added to the list
print spouse()
</code></pre>
<p>谢谢你的帮助。你知道吗</p>