0
Why is it that the names.append(person) and return “—-“ are not executed after the for loop? Ok
names = ["felix", "rona", "feona", "rozy"] def find(person): for name in names: if name == person: return "This person is already in database" names.append(person) return "Successfully added." print(find("feona"))
1 Odpowiedź
0
they are not executed because the execution ends when the line "if name == person:" is true, at this point the return statement on the next line is executed, so the function terminates
if you call the function with a name which is not included into the list "names", the function should execute "names.append(person)" and "return 'successfully added' "