I am working on a function that would take an user's input for four people's names and to append them to a list. However with the code below I get this user error. However, when I declare significant_other as a global variable, I get an invalid syntax error. How would I fix my 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
Here is the 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()
Thanks for your help with this.