Build a User Configuration Manager - Build a User Configuration Manager (bug?)

Tell us what’s happening:

possible bug? “your code has an error. Please fix before trying to run your code.” not even VS Code tells me there is an error.

Your code so far

def add_setting(dictionary, to_add):
    new_key = to_add[0].lower()
    new_value = to_add[1].lower()
    
    if new_key in dictionary:
        return f'Setting \'{to_add[0]}\' already exists! Cannot add a new setting with this name.'
    if new_key not in dictionary:
        return f'Setting \'{to_add[0]}\' added with value \'{to_add[1]}\' successfully!'

test_dict = {
    'stuff': 'wee'
}
tup_add = ('WEE', 'stuff')
add_setting({'theme': 'light'}, ('volume', 'high'))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:153.0) Gecko/20100101 Firefox/153.0

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-user-configuration-manager/684aaf9ec670c68d20efd0d0.md at main · freeCodeCamp/freeCodeCamp · GitHub

The warning is likely from the challenge tests, not VS Code. In your add_setting code, the function never updates the dictionary, so the test can still fail even when the editor shows no error.

scroll down until you see the tests, what is the first failing one?

So I added test_settings and that fixed the previous issue but now I don’t know which way to lowercase the key value pair tuple that is going to work for the checks. The 3 different ways I’ve tried all put them to lowercase including dictionary comprehension and as shown in the first post of code that I posted originally but still fail the checks.

Hi @kthomp2030,

This was good advice. Why did you completely change everything else in your function?

You might want to review this theory lecture about how to update/add to a dictionary:
Working with Dictionaries and Sets - What Are Dictionaries, and How Do They Work? | Learn | freeCodeCamp.org

Here’s an excerpt from that theory lecture:

To update a value, you just need to add the assignment operator, followed by the new value.
If the key doesn’t exist in the dictionary, a new key-value pair will be created.

pizza['name'] = 'Margherita'

I’d also like to point out that in your original code you created variables to store the lowered key/value pair passed to the function. But then when you return your messages, you use the values you assigned to the variables, without lowering them, rather than the variables themselves.

Please test your code by wrapping your function calls in print() so you can see what your function returns in the console:
print(add_setting({'theme': 'light'}, ('THEME', 'dark')))

Happy coding

In the snippet, item.lower only references the method, so the tuple keeps the original casing. Call it while building new_add, then unpack the lowered values; that matches the test’s expected lowercase key and value.