Build a User Configuration Manager - Build a User Configuration Manager

Tell us what’s happening:

I’ve tried converting the string to lower case in multiple ways and I would still see test cases 4 and 5 aren’t passed yet. Where as similar way, I converted to lower case in update_setting function which worked perfectly. Can anyone please help how to solve this ?

Your code so far


test_settings= {'theme':'dark','notifications':'enabled', 'volume':'high'}

def add_setting(settings, keys):
    key = keys[0].lower()
    value = keys[1].lower()
    if key in settings.keys():
        return f"Setting '{key}' already exists! Cannot add a new stting with this name."
    else:
        return f"Setting '{key}' added with value '{value}' successfully!"
    

def update_setting(settings, keys):
    key = keys[0].lower()
    value = keys[1].lower()
    if key in settings.keys():
        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."

def delete_setting(settings, key):
    key = key.lower()
    if key in settings.keys():
        settings.pop(key,'0')
        return f"Setting '{key}' deleted succesfully!"
    else:
        return "Setting not found!"

def view_settings(settings):
    if len(settings.items()) ==0:
        return "No settings available."
    else:
        print("Current User Settings:")
        for key,value in settings.items():
            print(f"{key.title()}: {value}")

print(view_settings(test_settings))


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:144.0) Gecko/20100101 Firefox/144.0

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

this is not the key tho? are you asked to transform the value in some way? please double check

yes, both key and value should be converted to lower case. so are 4 and 5 test cases.

are you adding the new setting to the object?

check

settings_in_test = {"theme": "light"}
result = add_setting(settings_in_test, ("volume", "HIGH"))
print('settings after adding', settings_in_test)
print('result', result)

I’m having a similar problem.

test_settings = {
    'brightness': 'low',
    'battery': 72,
    'notifications': True
}

def add_setting(settings, key_value_pair):
    updated_pair = tuple(i.lower() if isinstance(i, str) else i for i in key_value_pair)
    key = updated_pair[0]
    value = updated_pair[1]

    if key in settings:
        return f"Setting {key} already exists! Cannot add a new setting with this name."
    
    test_settings[str(key)] = value
    return f"Setting \'{key}\' added with value \'{value}\' successfully!"
    
print(add_setting(test_settings, ('poWEr', 'True')))
print(test_settings)
  • Failed: 4. add_setting should convert the key to lowercase.

  • Failed: 5. add_setting should convert the value to lowercase.

Does anyone know the solution to this yet?

I tried finding a solution here: ie this line \/

updated_pair = tuple(i.lower() if isinstance(i, str) else i for i in key_value_pair)

but still does not work

please create your own topic

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

Are you returning from your else clause?

All the manual test cases are working as expected when we try to print and validate. But somehow, it doesn’t work with hidden test cases.

While validating these 2 lines, I found that I forgot to update the dictionary back but wast just printing.