I seem to have to define this global variable in my code twice to remove errors which cant be right. The code just asks to input an object and adds it to a new list. If the user wants to skip this step he can let the new list = an old listed created earlier in the code.
I am must have the syntax wrong somewhere but cant figure out where. My code is below, grateful for any help thanks.
global new_object_list
def get_input_object(prompt):
global new_object_list
# new_object_list is defined without usage
new_object_list = []
while True:
chosen_object = input(prompt)
if chosen_object in my_list:
new_object_list.append(chosen_object)
# allows user to break out of loop on carriage return
if chosen_object == '\r':
break
# allows user to let new list = copy of old list then exit input
if chosen_object == 'all':
new_object_list = my_list.copy()
break
# return outside of function
return chosen_object
print(get_input_object('Enter entities separated by space'))
print(new_object_list)