Build a User Configuration Manager - Build a User Configuration Manager

Tell us what’s happening:

Hello,
I have been working on the first function described by this assignment. The code I am using now works and gives me the expected result when I print out the function and the updated test_settings. However, there are 2 problems. The first is that this code does not satisfy steps 4-7 even though it does satisfy 1, 2, 3, and 8. Furthermore, when I print the results, there is a “None” that appears after the “Success” message. Where am I going wrong in the code?

Your code so far

test_settings= {
    "volume": "high",
    "Last login Date": "Feb, 11, 2026",
    "theme": "light",
    "notifications": "enabled"
}
def add_setting (dictionary, item):
    key=str(item[0].lower())
    value=str(item[1].lower())
    if key in test_settings:
        print(f"Setting '{key}' already exists! Cannot add a new setting with this name.")
    else:
        dictionary.update({key: value})
        print(f"Setting '{key}' added with value '{value}' successfully!")
print(add_setting(test_settings, ("train", "locomotive")))
print(test_settings)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

try to make this change, in this line:

print(add_setting(test_settings, ("train", "locomotive")))

make it

print("result", add_setting(test_settings, ("train", "locomotive")))

you should see more clearly where the None is coming from

Hint: ||Are you sure your function is returning something?||

Alright. I replaced the “print” with return in my code and that has eliminated the “None” that prints on the terminal, though I am still seeing that I am not satisfying steps 4-7, even though step 8 is satisfied.

where does test_settings come from? is it a function parameter?

Its the name of the dictionary that I am trying to update with the function. It is to be the first argument in the function, while the following tuple is meant to be the key-value pair.

why do you have the function parameter if you then write if key in test_settings: inside the function?

test_settings is the argument you passed to add_settting, but dictionary is the parameter that argument was passed to; so in your function, you should always use the parameter. You are flip-flopping between test_settings and dictionary in the body of your function.

I changed that and the code passes. I appreciate your help with this.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.