im on the last steps, step 25 and 27 are failing, the challenges are
-
25.
view_settingsshould return formatted settings for non-empty dictionary. -
27.
view_settingsshould display the correct results and end with a newline character.
i really dont know, ive been stuck on this for hours and i have tried many different things, this is currently where i am and i think i dont even need the last part i added
user_settings = displays
heres what i have so far, i think this is the closest i have managed to get it and i cant seem to get it to pass, everything looks like what its asking
# a test dictionary of a users settings
test_settings = {
'theme': 'light',
'notifications': 'enabled',
'volume': 'high'
}
displays = ("Current user settings:""\n")
# a list of available settings
setting_list = ('theme', 'notifications', 'volume')
# adding a new user setting
def add_setting(test_settings, setting_new):
# convert the key and value to lowercase
key, value = setting_new
key = key.lower()
value = value.lower()
# check if the setting already exists and perform action
if key in test_settings:
return f"Setting '{key}' already exists! Cannot add a new setting with this name."
else:
test_settings[key] = value
return f"Setting '{key}' added with value '{value}' successfully!"
# updating user setting
def update_setting(test_settings, setting_new):
# convert the key and value to lowercase
key, value = setting_new
key = key.lower()
value = value.lower()
# check if the setting exists and perform action
if key in test_settings:
test_settings[key] = value
return f"Setting '{key}' updated to '{value}' successfully!"
else:
return f"Setting '{key}' does not exist! Cannot update a non-existing setting."
#delete user setting
def delete_setting(test_settings, setting_new):
# convert the key and value to lowercase
key = setting_new
key = key.lower()
# check if the setting exists and perform action
if key in test_settings:
del test_settings[key]
return f"Setting '{key}' deleted successfully!"
else:
return f"Setting not found!"
#view user settings
def view_settings(test_settings):
# format contents of non-empty dictionary
if not test_settings:
return f"No settings available."
if test_settings:
for key, value in test_settings.items():
display = f"{key.capitalize()}: {value.lower()}" + "\n"
global displays
displays += display
user_settings = displays
print(displays)
return displays
# add_setting test
add_setting({'theme': 'light'}, ('THEME', 'dark'))
# update_setting test
update_setting({'theme': 'light'}, ('theme', 'dark'))
# delete_setting test
delete_setting({'theme': 'light'}, 'theme')
# view_setting test
view_settings(test_settings)
print(repr(displays))