Tell us what’s happening:
The output is showing correctly on the console but when I’m clicking on test code it’s asking me to convert the key to lowercase in update_setting. I have done that as well I’m not sure why It’s saying that. Can someone please tell me what’s going wrong?
Your code so far
def add_setting(settings,pair):
input_key=pair[0].lower()
input_value=pair[1].lower()
for key in settings:
key=key.lower()
if input_key == key:
found = True
break
else:
found = False
continue
if found:
return f"Setting '{input_key}' already exists! Cannot add a new setting with this name."
if not found:
new_setting={input_key:input_value}
settings.update(new_setting)
return f"Setting '{input_key}' added with value '{input_value}' successfully!"
#print(settings)
def update_setting(settings,pair):
input_key=pair[0].lower()
input_value=pair[1].lower()
for key in settings:
key=key.lower()
if input_key == key:
found = True
break
else:
found = False
continue
if found:
settings[input_key.title()]=input_value
return f"Setting '{input_key}' updated to '{input_value}' successfully!"
if not found:
return f"Setting '{input_key}' does not exist! Cannot update a non-existing setting."
def delete_setting(settings,pair):
input_key=pair[0].lower()
input_value=pair[1].lower()
for key in settings:
key=key.lower()
if input_key == key:
found = True
break
else:
found = False
continue
if found:
del settings[input_key.title()]
return f"Setting '{input_key}' deleted successfully!"
if not found:
return "Setting not found!"
def view_settings(settings):
if settings == {}:
return "No settings available."
else:
output = ""
#print("Current User Settings:")
for setting, mode in settings.items():
output += f"{setting.title()}: {mode}\n"
return output
test_settings={
'Current User Settings':'',
'Theme': 'dark',
'Notifications': 'enabled',
'Volume': 'high'
}
User_input = ('background','blue')
add_setting(test_settings,User_input)
#print(test_settings)
add_setting(test_settings,User_input)
print(update_setting({'theme': 'light'},("theme","dark")))
#print(test_settings)
delete_setting(test_settings,('volume', 'high'))
#print(test_settings)
print(view_settings(test_settings))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Challenge Information:
Build a User Configuration Manager - Build a User Configuration Manager