function global/local variable update issues

Viewed 59

Can someone point out why this function is not outputting? Please explain and give examples. I am just unable to figure out the issue.

def double(lst):

    count=0
    result='Found'
    lsy=[count,result]

    for i in lst:
        word=i
        if 'mm' in word:
            result='Found'
            count=0
            break
        if 'nn' in word:
            result='None'
            count+=1

    return lsy

double(['Ammy','Timmy','Jimmy'])
3 Answers
result = double(['Ammy','Timmy','Jimmy'])
print(result)
# [0, 'Found']

use print() on your function call. Otherwise nothing is given to stdout, hence why you see nothing.

If you meant that the function is producing a wrong result then the problem lies in lsy because you do not update it with the result after you process the result inside the for loop.

If you really meant that you are not getting the output displayed then simply print the result:

print(double(['Ammy', 'Timmy', 'Jimmy']))

Related