User configuration manager final steps please help

im on the last steps, step 25 and 27 are failing, the challenges are

  • 25. view_settings should return formatted settings for non-empty dictionary.

  • 27. view_settings should display the correct results and end with a newline character.

i really dont know, ive been stuck on this for hours and i have tried many different things, this is currently where i am and i think i dont even need the last part i added

user_settings = displays

heres what i have so far, i think this is the closest i have managed to get it and i cant seem to get it to pass, everything looks like what its asking

# a test dictionary of a users settings
test_settings = {
    'theme': 'light',
    'notifications': 'enabled',
    'volume': 'high'
}
displays = ("Current user settings:""\n")
# a list of available settings
setting_list = ('theme', 'notifications', 'volume')

# adding a new user setting 
def add_setting(test_settings, setting_new):

# convert the key and value to lowercase
    key, value = setting_new
    key = key.lower()
    value = value.lower()

# check if the setting already exists and perform action
    if key in test_settings:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
    
    else:
        test_settings[key] = value
        return f"Setting '{key}' added with value '{value}' successfully!"

# updating user setting
def update_setting(test_settings, setting_new):

# convert the key and value to lowercase
    key, value = setting_new
    key = key.lower()
    value = value.lower()

# check if the setting exists and perform action
    if key in test_settings:
        test_settings[key] = value
        return f"Setting '{key}' updated to '{value}' successfully!"
    else:
        return f"Setting '{key}' does not exist! Cannot update a non-existing setting."
   
#delete user setting
def delete_setting(test_settings, setting_new):

# convert the key and value to lowercase
    key = setting_new
    key = key.lower()

# check if the setting exists and perform action
    if key in test_settings:
        del test_settings[key]
        return f"Setting '{key}' deleted successfully!"
    else:
        return f"Setting not found!"
    
#view user settings
def view_settings(test_settings):

# format contents of non-empty dictionary
    if not test_settings:
        return f"No settings available."
    if test_settings:
        for key, value in test_settings.items():
            display = f"{key.capitalize()}: {value.lower()}" + "\n"
            global displays
            displays += display
    user_settings = displays
    print(displays)
    return displays
               
            


# add_setting test
add_setting({'theme': 'light'}, ('THEME', 'dark'))
# update_setting test
update_setting({'theme': 'light'}, ('theme', 'dark'))
# delete_setting test
delete_setting({'theme': 'light'}, 'theme')
# view_setting test
view_settings(test_settings)
print(repr(displays))

oh, when i go back to update:

print(repr(view_settings(test_settings)))

I see that for some reason, its updating everything twice, so that my output is something like this

'Current user settings:\nTheme: light\nNotifications: enabled\nVolume: high\nTheme: light\nNotifications: enabled\nVolume: high\n'

i dont know where to begin to stop it from updating everything twice and i have tried multiple things.

Could you link to the challenge in question?

i linked both. they are the second to last post. i know that my response to the challenge is repeating double, i just dont know why that is.

link in OP sorry it wasnt clear.

I somehow cannot find the link in the first post… Could you link it again?

yes, sorry. it was in the first post.

25. view_settings should return formatted settings for non-empty dictionary.

27. view_settings should display the correct results and end with a newline character.

This is because view_settings function relies on global variable to create the string with settings, and each time view_settings is called, current settings are added again.

1 Like

that function is only called once in the whole script so i dont understand that. also i did it that way because for some reason i couldnt get it to iterate the whole dictionary, it would iterate the first item theme then stop.
ill see if i can figure out why, maybe it will fix the problem.