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
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.
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.
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')))
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.