Build a User Configuration Manager - Build a User Configuration Manager

Tell us what’s happening:

Hi All! I can’t figure out why my code passes all the tests related to building the functions, but not the ones with example cases. Should I be testing the code differently for it to count? I’m lost on how the code is actually validated

Your code so far

test_settings = { 'volume' : '10', 'sound' : 'off'}
test_settings_empty = {}

def add_setting(dict_settings, new_settings):
    key_lowercase = new_settings[0].lower()
    value_lowercase = new_settings[1].lower()

    if key_lowercase in dict_settings:
        print(f"Setting '{key_lowercase}' already exists! Cannot add a new setting with this name.")
    else:
        dict_settings.update({key_lowercase : value_lowercase})
        print(f"Setting '{key_lowercase}' added with value {value_lowercase} successfully!")

        #Print new dict for test
        #print(dict_settings)

def update_setting(dict_settings, new_settings):
    key_lowercase = new_settings[0].lower()
    value_lowercase = new_settings[1].lower()

    if key_lowercase in dict_settings:
        dict_settings[key_lowercase] = value_lowercase
        print(f"Setting '{key_lowercase}' updated to {value_lowercase} successfully!")

        #Print new dict for test
        #print(dict_settings)

    else:
        print(f"Setting '{key_lowercase}' does not exist! Cannot update a non-existing setting.")

def delete_setting(dict_settings, key):
    key_lowercase = key.lower()

    if key_lowercase in dict_settings:
        del dict_settings[key_lowercase]
        print(f"Setting '{key_lowercase}' deleted successfully!")

        #Print new dict for test
        #print(dict_settings)

    else:
        print('Setting not found!')

def view_settings(dict_settings):
    if dict_settings == {}:
        return 'No settings available.'
    else:
        result_string = 'Current User Settings: \n'
        for item in dict_settings:
            capitalized_key = item.capitalize()
            result_string += capitalized_key
            result_string += " : "
            result_string += dict_settings[item]
            result_string += "\n"
        return result_string

    
# Test 6
# add_setting({'theme': 'light'}, ('THEME', 'dark'))

# Test 7
# add_setting({'theme': 'light'}, ('volume', 'high'))

#Test 13
# update_setting({'theme': 'light'}, ('theme', 'dark'))

# Test 14
# update_setting({'theme': 'light'}, ('volume', 'high'))

# Test 19
# delete_setting({'theme': 'light'}, 'theme')

# Test 20
# delete_setting(test_settings, 'color')

#Test 24
#print(view_settings(test_settings_empty))

#Test 25, 26, 27
#print(view_settings(test_settings))

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

add_setting({'theme': 'light'}, ('THEME', 'dark'))

should return the error message

Setting 'theme' already exists! Cannot add a new setting with this name.

And here is what is displayed in the console.

Setting ‘theme’ already exists! Cannot add a new setting with this name.
None

Why do you suppose you are seeing None in the console?

How did you run the code for this None to appear? In the challenge page itself? It doesn’t show to me, maybe I’m checking the results wrongly as well

print(add_setting({'theme': 'light'}, ('THEME', 'dark')))

1 Like

Got it, I was not running “print” while calling the function.

Is it necessary, since the function itself already prints the result?

Should it? Why do you think None is appearing in the console?

Please review again what your first failing test says. You are missing something important in the instructions.

Thank you, think I got it. Will try to fix it and update here

No need to post your updated code unless you need more help. Thank you.

I was able to pass all tests but 27 by having the functions return the results instead of printing. (duh)

My view_settings function looks like this:

def view_settings(dict_settings):

    if dict_settings == {}:

return 'No settings available.'

else:

        result_string = 'Current User Settings: \n'

for item in dict_settings:

            capitalized_key = item.capitalize()

            result_string += capitalized_key

            result_string += ": "

            result_string += dict_settings[item]

            result_string += "\n"

return result_string

And when I run the example provided on the instructions (view_settings({‘theme’: ‘dark’, ‘notifications’: ‘enabled’, ‘volume’: ‘high’})), it gives the exact same result, including a new line after the last item.

Please share your full code if you still need assistance.

But what about this? Check spacing.

Got it now, it really was the extra spacing. Thanks master