Update value from a library in function

Hi there,

I have a code here:

def make_album(artist_name, album_title, number_songs=None):
    """Return information of albums."""
    albums = {'artist_name': artist_name, 'album_title': album_title}
    if number_songs:
        albums['number of songs'] = number_songs
    return albums

while True:
    print("\nPlease enter the album's information.")
    print("Enter 'q' to quit the program.")
    a_name = input("What is the artist's name? ")
    if a_name == 'q':
    a_title = input("What is the album title? ")
    if a_title == 'q':
    no_songs = input("Do you know how many songs are in the album? (yes / no)")
    if no_songs == 'no':
        number_songs = None
    elif no_songs == 'yes':
        n_songs = int(input("How many songs are there? "))
    elif no_songs == 'q':
    album_info = make_album(a_name, a_title, n_songs)

The first library looks good after entering answers. However, if I answer ‘no’ for question “Do you know how many songs are in the album? (yes / no)” on the second try, the dictionary will still have number of songs from the first try. Could someone please show me what the right way to change the value for number_songs is?

That’s because you’re still passing n_songs into the make_album() function, even when you answered “no”, where, instead of n_songs, you used a different variable number_songs. In this scenario, number_songs = None is basically ignored.

n_songs still has the number from the first try, so your second try shows the number from the first try.