Build a User Configuration Manager - Build a User Configuration Manager Task 4 & 5 failing

Tell us what’s happening:

Failed: 4. add_setting should convert the key to lowercase.

Failed: 5. add_setting should convert the value to lowercase.

I’ve tried multiple things, including searching here for a solution, (ex the current line that changes the variables/parameters to lowercase, although I have also tried simpler options, such as

key = key_value_pair[0].lower()
value = key_value_pair[1].lower()

Your code so far

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)

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

what if you need to update a different object?

That is not my current issue… I’m struggling to get test 4 & 5 to approve the code, I will try that though

After trying that it approved those two requirements. Why would I have to change a separate part of the code to approve those two?

because you made your function work only with test_settings. The tests would check with different objecst to verify that all the behaviours we want from the function are working correctly, and none of them were being changed by your code

1 Like