I’ve tried converting the string to lower case in multiple ways and I would still see test cases 4 and 5 aren’t passed yet. Where as similar way, I converted to lower case in update_setting function which worked perfectly. Can anyone please help how to solve this ?
Your code so far
test_settings= {'theme':'dark','notifications':'enabled', 'volume':'high'}
def add_setting(settings, keys):
key = keys[0].lower()
value = keys[1].lower()
if key in settings.keys():
return f"Setting '{key}' already exists! Cannot add a new stting with this name."
else:
return f"Setting '{key}' added with value '{value}' successfully!"
def update_setting(settings, keys):
key = keys[0].lower()
value = keys[1].lower()
if key in settings.keys():
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."
def delete_setting(settings, key):
key = key.lower()
if key in settings.keys():
settings.pop(key,'0')
return f"Setting '{key}' deleted succesfully!"
else:
return "Setting not found!"
def view_settings(settings):
if len(settings.items()) ==0:
return "No settings available."
else:
print("Current User Settings:")
for key,value in settings.items():
print(f"{key.title()}: {value}")
print(view_settings(test_settings))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:144.0) Gecko/20100101 Firefox/144.0
Challenge Information:
Build a User Configuration Manager - Build a User Configuration Manager
test_settings = {
'brightness': 'low',
'battery': 72,
'notifications': True
}
def add_setting(settings, key_value_pair):
updated_pair = tuple(i.lower() if isinstance(i, str) else i for i in key_value_pair)
key = updated_pair[0]
value = updated_pair[1]
if key in settings:
return f"Setting {key} already exists! Cannot add a new setting with this name."
test_settings[str(key)] = value
return f"Setting \'{key}\' added with value \'{value}\' successfully!"
print(add_setting(test_settings, ('poWEr', 'True')))
print(test_settings)
Failed: 4. add_setting should convert the key to lowercase.
Failed: 5. add_setting should convert the value to lowercase.
Does anyone know the solution to this yet?
I tried finding a solution here: ie this line \/
updated_pair = tuple(i.lower() if isinstance(i, str) else i for i in key_value_pair)
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.
The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.