I’m struggling to validate 25, 26, 27 running test. I’ve got the right output and the code seems to work but not validate running tests. Would you help me with some advices or hint to manage this exercice ?
Thanks for your time !
Your code so far
def add_setting(settings, values):
key, value = values
key = key.lower()
value = value.lower()
if key in settings:
return f"Setting '{key}' already exists! Cannot add a new setting with this name."
else:
settings.update({key: value})
return f"Setting '{key}' added with value '{value}' successfully!"
print(add_setting({'theme': 'light'}, ('THEME', 'dark')))
print(add_setting({'theme': 'light'}, ('volume', 'high')))
def update_setting(settings, values):
key, value = values
key = key.lower()
value = value.lower()
if key in settings:
settings.update({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, values):
key = values
key = key.lower()
if key in settings:
settings.pop(key)
return f"Setting '{key}' deleted successfully!"
else:
return "Setting not found!"
print(delete_setting({'theme': 'light'}, 'theme'))
def view_settings(settings):
if not settings:
return f'No settings available.'
else:
print(f'Current User Settings:')
for key, value in settings.items():
print(f'{key.capitalize()}: {value.lower()}')
print(view_settings({'theme': 'dark', 'notifications': 'enabled', 'volume': 'high'}))
test_settings = {
'Theme': 'Dark',
'Notifications': 'Enabled',
'Volume': 'High'
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Challenge Information:
Build a User Configuration Manager - Build a User Configuration Manager
Should you be printing the user settings or returning them?
view_settings should display the correct results and end with a newline character.
Are there newline characters?
You can test with : print(repr(view_settings(test_settings))) after you move your test settings declaration so it is defined before the function call.
One other thing, does it make sense to create a test_settings dictionary with capitalized key/value pairs when you always lower() those in your add_setting and update_setting methods?
def view_settings(settings):
if not settings:
return f'No settings available.'
result = 'Current User Settings:'
for key, value in settings.items():
result += f'\n{key.capitalize()}: {value.lower()}'
return (f'{result}\n')
print(view_settings({'theme': 'dark', 'notifications': 'enabled', 'volume': 'high'}))
print(repr(view_settings(test_settings)))
Thanks for your help, i modify a bit the code for me, more readable.
I tried your command : print(repr(view_settings(test_settings)))
Here is the output : ‘Current User Settings:\nTheme: dark\nNotifications: enabled\nVolume: high\n’
Were you asked to lower() value? Does that even make sense if add_setting and update_setting are always lowering the key/value pairs in the dictionary?