Tell us what’s happening:
I don’t know why but my code won’t even run, it won’t let me run the code because it shows up as an error but on the terminal nothing shows up.
Your code so far
test_settings = {
"brightness": 80,
"volume": 57,
"screen_mode": "dark",
"theme": "dark"
}
def add_setting(settings, new_setting):
key, val = key_value
key = key.lower()
val = value.lower()
if key in settings.keys():
return f"Setting '{key}' already exists! Cannot add a new setting with this name."
else:
return f"Setting '{key}' added with value '{val}' successfully!"
def update_setting(settings, new_setting):
key, val = key_value
key = key.lower()
val = value.lower()
if key in settings.keys():
return f"Setting '{key}' updated to '{val}' successfully!"
else:
return f"Setting '{key}' does not exist! Cannot updae a non-existing setting."
def delete_setting(settings, item):
key = key.lower()
if key in settings.key():
return f"Setting '{key}' deleted successfully!"
else:
return 'Setting not found!'
def view_settings(settings):
if settings == '':
return 'No settings available.'
else:
return f"Current User Settings: '{settings}'"
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Challenge Information:
Build a User Configuration Manager - Build a User Configuration Manager
dhess
March 30, 2026, 4:10pm
2
Hi @selina_chen ,
Where is key_value defined in your code?
You need to call your function to test it: print(add_setting(test_settings, ('WI-FI','On'))
Happy coding!
It says add_setting isn’t defined, I don’t understand how it works now
dhess
March 30, 2026, 4:16pm
4
Blooper on my part with the print code. I’ve edited it. Please try again.
I don’t know how to proceed, I’ve removed the key_value but there’s an error showing up: UnboundLocalError: cannot access local variable ‘key’ where it is not associated with a value
dhess
March 30, 2026, 6:17pm
6
Please post your updated code.
test_settings = {
"brightness": 80,
"volume": 57,
"screen_mode": "dark",
"theme": "dark"
}
def add_setting(settings, new_setting):
key = key.lower()
val = value.lower()
if key in settings.keys():
return f"Setting '{key}' already exists! Cannot add a new setting with this name."
else:
return f"Setting '{key}' added with value '{val}' successfully!"
def update_setting(settings, new_setting):
key = key.lower()
val = value.lower()
if key in settings.keys():
return f"Setting '{key}' updated to '{val}' successfully!"
else:
return f"Setting '{key}' does not exist! Cannot updae a non-existing setting."
def delete_setting(settings, item):
key = key.lower()
if key in settings.key():
return f"Setting '{key}' deleted successfully!"
else:
return 'Setting not found!'
def view_settings(settings):
if settings == '':
return 'No settings available.'
else:
return f"Current User Settings: '{settings}'"
print(add_setting(test_settings, ('WI-FI','On')))
dhess
March 30, 2026, 6:31pm
8
Again, where is key and value defined in your code?
how exactly do i define it? as in with what values and do i make it a global scope?
dhess
March 30, 2026, 6:45pm
10
You use the values that are passed to the function in your function call. You should not be using any global-scoped variable directly in your function. Use the function parameters.
I replaced the key and val with my parameters settings and new_settings however it shows this error: AttributeError: ‘dict’ object has no attribute ‘lower’
dhess
March 30, 2026, 6:55pm
12
Post your updated code for that bit.
test_settings = {
“brightness”: 80,
“volume”: 57,
“screen_mode”: “dark”,
“theme”: “dark”
}
def add_setting(settings, new_setting):
settings = settings.lower()
new_setting = new_setting.lower()
if setting in settings.keys():
return f"Setting '{setting}' already exists! Cannot add a new setting with this name."
else:
return f"Setting '{setting}' added with value '{new_setting}' successfully!"
def update_setting(settings, new_setting):
settings = settings.lower()
new_setting = new_setting.lower()
if setting in settings.keys():
return f"Setting '{setting}' updated to '{new_setting}' successfully!"
else:
return f"Setting '{setting}' does not exist! Cannot updae a non-existing setting."
def delete_setting(settings, item):
settings = settings.lower()
if setting in settings.key():
return f"Setting ‘{setting}’ deleted successfully!"
else:
return ‘Setting not found!’
def view_settings(settings):
if settings == ‘’:
return ‘No settings available.’
else:
return f"Current User Settings: ‘{settings}’"
print(add_setting(test_settings, (‘WI-FI’,‘On’)))
dhess
March 30, 2026, 7:00pm
14
When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add the backticks.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
test_settings = {
"brightness": 80,
"volume": 57,
"screen_mode": "dark",
"theme": "dark"
}
def add_setting(settings, new_setting):
settings = settings.lower()
new_setting = new_setting.lower()
if setting in settings.keys():
return f"Setting '{setting}' already exists! Cannot add a new setting with this name."
else:
return f"Setting '{setting}' added with value '{new_setting}' successfully!"
def update_setting(settings, new_setting):
settings = settings.lower()
new_setting = new_setting.lower()
if setting in settings.keys():
return f"Setting '{setting}' updated to '{new_setting}' successfully!"
else:
return f"Setting '{setting}' does not exist! Cannot updae a non-existing setting."
def delete_setting(settings, item):
settings = settings.lower()
if setting in settings.key():
return f"Setting '{setting}' deleted successfully!"
else:
return 'Setting not found!'
def view_settings(settings):
if settings == '':
return 'No settings available.'
else:
return f"Current User Settings: '{settings}'"
print(add_setting(test_settings, ('WI-FI','On')))
dhess
March 30, 2026, 9:01pm
16
Please review this theory lecture thoroughly:
Working with Dictionaries and Sets - What Are Dictionaries, and How Do They Work? | Learn | freeCodeCamp.org
Then look at the arguments you are passing to the function parameters in your function call.
The parameter settings will have the value of test_settings, which is a dictionary.
The parameter new_setting will have the value of your second argument, the tuple ('WI-FI','On').
Can you say what is the key and what is the value that you are trying to add to your dictionary?