This code has 2 functions one for taking a list from user and the other one should remove the duplications in this list , it can be done without using functions but im learning functions in Python.
How can I take the list that the user has entered in function take_list() and pass it to the function no_duplication() ?
when I do it i get this error
Unresolved reference 'k'
at the line : no_duplication(k)
def take_list():
k = []
i = 0
list_length = int(input("how many elements your list has ? \n "))
while i < list_length:
element = int(input("enter you list elements : "))
k.append(element)
i += 1
print(k, " is your list")
return k
def no_duplication(k):
k = set(k)
k = list(k)
print(k, " Your list without duplications")
take_list()
no_duplication(k)
kis undefined in the last line of your code. You wantk=take_list()and thenno_duplication(k). Or, taken together, you can do:no_duplication(take_list()).kink = take_list()is different variable fromkused inside the function body. One can use different name if they want.