Build a User Configuration Manager - Build a User Configuration Manager

Tell us what’s happening:

OK, so I have written most of the code of this exercise, and even though I have the needed message printed on the terminal when calling “add_setting({‘theme’: ‘light’}, (‘THEME’, ‘dark’))” for the step to be marked as correct, the system won’t mark it as correct. I’ve changed everything I could think of, and I don’t see what my error is.
Somebody please tell me what am I doing wrong(((

Your code so far

def add_setting(settings, tup):
    key, value = [item.lower() for item in tup]
    if key in settings:
        key_not_added = print(f"Setting '{key}' already exists! Cannot add a new setting with this name.")
        return key_not_added
    if key not in settings:
        settings.update({key:value})
        key_added = print(f"Setting '{key}' added with value '{value}' successfully!.")
        return key_added
    return key_not_added, key_added
def update_setting(settings, tup):
    key, value = [item.lower() for item in tup]
    if key in settings: 
        settings[value] = tup[1]
        setting_upadte = print(f"Setting '{key}' updated to '{value}' successfully!")
        return setting_upadte
    if key not in settings: 
         not_setting = print(f"Setting '{key}' does not exist! Cannot update a non-existing setting.")
         return not_setting
    return setting_upadte, not_setting

def delete_setting(settings, tup):

    key = tup[0]
    key = key.lower()
    if key in settings:
            del settings[key]
            k_vPairDeleted = print(f"Setting '{key}' deleted successfully!")
            return k_vPairDeleted
    if key not in settings: 
            not_kvPair = print("Setting not found!")
            return not_kvPair
    return k_vPairDeleted, not_kvPair
         


test_settings = {
        "Volume": "high",
        "notifications": "enabled",
        "theme": "dark"
    } 

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-user-configuration-manager/684aaf9ec670c68d20efd0d0.md at main · freeCodeCamp/freeCodeCamp · GitHub

the tests will be checking the output of your function

you can see what your function is returning by putting the function call in a print call

print("The output of my function is", add_setting({'theme': 'light'}, ('THEME', 'dark')))

image

this is what happens when you return a print, because print’s output is None

I’ve corrected that already, figured it out, and changed it. Now I have another problem. My script is not passing the 11th test, but I don’t understand why; it seems to me that both values from the tuples are being converted into lowercase. I did the same with the values of the tuple from add_setting(), and it worked.

def add_setting(settings, tup):

key, value = tup 

key= key.lower()

value = value.lower()

if key in settings:

    return f"Setting '{key}' already exists! Cannot add a new setting with this name."

    return key_not_added

if key not in settings:

    settings.update({key:value})

    return f"Setting '{key}' added with value '{value}' successfully!"

def update_setting(settings, tup):

key, value = tup 

key = key.lower()

value = value.lower()

if key in settings: 

    settings\[value\] = tup\[1\]

    return f"Setting '{key}' updated to '{value}' successfully!"

if key not in settings: 

     return f"Setting '{key}' does not exist! Cannot update a non-existing setting."

def delete_setting(settings, tup):

key = tup\[0\]

key = key.lower()

if key in settings:

        del settings\[key\]

        return f"Setting '{key}' deleted successfully!"

if key not in settings: 

        return "Setting not found!"

def view_setting(settings):

 if not settings: 

      return 'No settings available.'

 if settings:

    print('Current User Settings\\n')

    for key, value in settings.items():

        print(f'{key}: {value}\\n')

test_settings = {

    "Theme": "dark",

    "Notifications": "enabled",

    "Volume": "high",

} 

add_setting({‘theme’: ‘light’}, (‘THEME’, ‘dark’))

add_setting({‘theme’: ‘light’}, (‘volume’, ‘high’))

update_setting({‘theme’: ‘light’}, (‘theme’, ‘dark’))

delete_setting({‘theme’: ‘light’}, ‘theme’)

There are two ways you can format your code to make it easier to read and test:

  1. After you copy/paste your code into the editor, select it by dragging your cursor over it then click the (</>) button in the toolbar to automatically wrap your code in backticks. (You can click on the animated demo image below to enlarge it.)

  1. Manually add three backticks on a new line above your code and on a new line after your code. Note that a backtick is NOT the same as a single quote('). To find the backtick key on your keyboard, see this post.

To see changes to your post as you make them, you can click the (M+) button on the toolbar to bring up the rich text editor:

Sorry about that; that is something I didn’t know and I appreciate that you took the time to explain it to me.
This is my code’s script in the right format to be tested. I’ve been rewriting and changing things and still cannot figure it out.I beforehand thank you for your help.

def add_setting(settings, tup):

    key, value = tup 

    key= key.lower()

    value = value.lower()

    if key in settings:

        return f"Setting '{key}' already exists! Cannot add a new setting with this name."

        return key_not_added

    if key not in settings:

        settings.update({key:value})

        return f"Setting '{key}' added with value '{value}' successfully!"





def update_setting(settings, tup):

    key, value = tup 

    key = key.lower()

    value = value.lower()

    if key in settings: 

        settings[value] = tup[1]

        return f"Setting '{key}' updated to '{value}' successfully!"

    if key not in settings: 

         return f"Setting '{key}' does not exist! Cannot update a non-existing setting."





def delete_setting(settings, tup):




    key = tup[0]

    key = key.lower()

    if key in settings:

            del settings[key]

            return f"Setting '{key}' deleted successfully!"

    if key not in settings: 

            return "Setting not found!"

            




def view_setting(settings): 

     if not settings: 

          return 'No settings available.'

     if settings:

        print('Current User Settings\n')

        for key, value in settings.items():

            print(f'{key}: {value}\n')

          

         

test_settings = {

        "Theme": "dark",

        "Notifications": "enabled",

        "Volume": "high",

    } 




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

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

update_setting({'theme': 'light'}, ('theme', 'dark'))

delete_setting({'theme': 'light'}, 'theme')



are you sure you are updating the correct setting here?

remind me what key and value are?