2

here is my script :

time_remaining = [1, 2, 3, 4]
url_links = ["a", "b", "c"]
nb_bookies = ['5', '7', '6']

def gitanerie(time, url, book):
    if len(time) != len(url):
        
        url = url.append('d')
        book = book.append('1')
        
    else:
        pass
    
    return url, nb_bookies

url_links, nb_bookies = gitanerie(time_remaining, url_links, nb_bookies)
print(url_links)
print(nb_bookies)

When I run it it gives me :

None
['5', '7', '6', '1']

the url_kinks is empty. How to solve this problem. Thanks

1
  • url.append('d') modifies the list in-place and returns None. Hence, don't reassign the return value. Commented Feb 3, 2021 at 11:46

2 Answers 2

2

Don't use in place url and book bacause append has no return type value rather follow this,

def gitanerie(time, url, book):
    if len(time) != len(url):
        url.append('d')
        book.append('1')
    else:
        pass
    return url, nb_bookies
Sign up to request clarification or add additional context in comments.

Comments

1

You are returning the wrong variables in your function and instead of book = book.append('d') use book.append('d')

time_remaining = [1, 2, 3, 4]
url_links = ["a", "b", "c"]
nb_bookies = ['5', '7', '6']

def gitanerie(time, url, book):
    if len(time) != len(url):
        url.append('d')
        book.append('1')
       
    else:
        pass
    return url, book
    
url_links, nb_bookies = gitanerie(time_remaining, url_links, nb_bookies)
print(nb_bookies,url_links)

This will result in:

['5', '7', '6', '1'] ['a', 'b', 'c', 'd']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.