Build a User Configuration Manager - Build a User Configuration Manager

Tell us what’s happening:

I am failing tests 15 and 21, and I am not sure why. I tried to verify that the calls of settings.pop() and settings.update where actually working with print statements, and it showed that it was being updated. Is there anything I missed?

Your code so far

test_settings = {
    'potato': 9,
    'watermelon': 'fifty'
}

def add_setting(settings: dict, new_setting: tuple):
    setting, value = new_setting
    setting = setting.lower()
    value = value.lower()
    for setting_key in settings.keys():
        if setting_key == setting:
            return f"Setting '{setting}' already exists! Cannot add a new setting with this name."
        else:
            settings.update({f'{setting}': f'{value}'})
            return f"Setting '{setting}' added with value '{value}' successfully!"

def update_setting(settings: dict, setting_update: tuple):
    setting, value = setting_update
    setting = setting.lower()
    value = value.lower()
    for setting_key in settings.keys():
        if setting_key == setting:
            # print(settings.items())
            settings.update({ setting: value })
            # print(settings.items())
            return f"Setting '{setting}' updated to '{value}' successfully!"
        else:
            return f"Setting '{setting}' does not exist! Cannot update a non-existing setting."

print(update_setting({'theme': 'light'}, ('theme', 'dark')))

def delete_setting(settings: dict, setting_delete: str):
    setting_delete = setting_delete.lower()
    for setting_key in settings.keys():
        if setting_key == setting_delete:
            # print(settings)
            settings.pop(f'{setting_delete}')
            # print(settings)
            return f"Setting '{setting_delete}' deleted successfully!"
        else: 
            return "Setting not found!"

delete_setting({'theme': 'light'},'theme')

def view_settings(settings):
    if settings.items() == dict([]).items():
        return "No settings available."
    else:
        settings_list = ''
        for setting, value in settings.items():
            settings_list += f'{setting.capitalize()}: {value}\n' 
        return 'Current User Settings:\n' + settings_list
view_settings(test_settings)

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:149.0) Gecko/20100101 Firefox/149.0

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

Just off a preliminary glance I do not believe this is the correct way to add the arguments to this method. Take a few steps back and check what it asks you to pass as arguments.

I also think that this for loop is unnecessary and i would look to change your == and instead use ‘in’

Could be taking a swing and a miss here but this appears to me to not complete the test correctly based on what they are asking and I would suggest a full rewrite of this method after reading over the lessons on dictionaries one more time and how to access items and in what syntax to do so in. I can link you some stuff

Your help made me realize that the issue was, that the for loop would return Setting not found! if the first key in setting.keys() was not equal to setting_delete, ending the function early. I realized that this was the issue update_setting() and delete_setting() because in my testing I called a dictionary where the first key was equal to the key I was targeting, meaning it would work correctly, but calling it with a dictionary with a different key then I was targeting, it would fail. Thank you for your help!

This code is fine. The syntax parameter : type is just providing a hint for what the parameter’s type is expected to be.

just finished the lessons where i learned what that was funny enough. Thanks for the reinforcement knowledge bro!