Tell us what’s happening:
-
For add_setting and update_setting, I do not meet the requirement that wants me to convert the key and values to lower case; is there another method I should be using?
-
For view_settings, why cant I return the strings in the way I did – it only shows ‘Current User Settings:’ and doesn’t show the actual key and value pairs.
Thanks
Your code so far
test_settings = {
'theme': 'dark',
'notifications': 'enabled',
'volume': 'high'
}
import re
def add_setting(dictionary, key_value):
key, val = key_value
key = key.lower()
val = val.lower()
key_list = str(dictionary.keys())
if re.search(key, key_list):
return f"Setting {key} already exists! Cannot add a new setting with this name."
else:
dictionary.update({'key': 'val'})
return f"Setting '{key}' added with value '{val}' successfully!"
def update_setting(dictionary, key_value):
key, val = key_value
key = key.lower()
val = val.lower()
key_list = str(dictionary.keys())
if re.search(key, key_list):
dictionary.update({'key': 'val'})
return f"Setting '{key}' updated to '{val}' successfully!"
else:
return f"Setting '{key}' does not exist! Cannot update a non-existing setting."
def delete_setting(dictionary, key):
key = key.lower()
key_list = str(dictionary.keys())
if not re.search(key, key_list):
return 'Setting not found!'
else:
del dictionary[key]
return f"Setting '{key}' deleted successfully!"
def view_settings(dictionary):
if dictionary == {}:
return 'No settings available.'
else:
return "Current User Settings:"
for key, val in dictionary.items():
return f"{key.capitalize()}: {val}"
print(add_setting({'theme': 'light'}, ('THEME', 'dark')))
print(add_setting({'theme': 'light'}, ('volume', 'high')))
print(update_setting({'theme': 'light'}, ('theme', 'dark')))
print(update_setting({'theme': 'light'}, ('volume', 'high')))
print(delete_setting({'theme': 'light'}, 'theme'))
print(view_settings({'theme': 'dark', 'notifications': 'enabled', 'volume': 'high'}) )
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15
Challenge Information:
Build a User Configuration Manager - Build a User Configuration Manager