Build a User Configuration Manager - Build a User Configuration Manager

Tell us what’s happening:

Setting ‘theme’ already exists! Cannot add a new setting with this name.
Setting ‘volume’ already exists! Cannot add a new setting with this name.
Setting’theme’ added with value 'dark’successfully!
Setting not found!
Current User Settings:
‘Theme’:‘dark’
‘Notifications’:‘enabled’
‘Volume’:‘high’
but its still showing errors

Your code so far

test_settings={'theme':'dark','notifications':'enabled','volume':'high'}

def add_setting(settings,key_value):
    key=key_value[0].lower()
    value=key_value[1].lower()
    if key in settings:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
    else:
         test_settings.update({key:value})
         return f"Setting '{key}' added with value '{value}' successfully!"
   

def update_setting(settings,key_value):
    key=key_value[0].lower()
    value=key_value[1].lower()
    if key in settings:
        test_settings.update({key:value})
        return f"Setting'{key}' added with value '{value}'successfully!"
    else:
        return f"Setting '{key}' does not exist! cannot update a '{key}':'{value}'non-existing setting."

def delete_setting(settings,key_value):  
    key=key_value[0].lower()
    if key in settings:



        del test_settings[key]
        return f"Setting '{key}' deleted successfully!."
    else:
        return f"Setting not found!"    
   

def view_settings(settings):
    str="Current User Settings:\n"
    if len(test_settings)==0:
        return "No settings available"
    else:    
        for kv in test_settings.items():
            key=kv[0].title()
            value=kv[1]
            str+=f"'{key}':'{value}'\n"
    return str 
print(add_setting(test_settings,('THEME','dark')))  
print(add_setting(test_settings,('Volume','high')))
print(update_setting(test_settings, ('theme','dark')))
print(delete_setting(test_settings, 'theme'))
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/144.0.0.0 Safari/537.36

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

1 Like

look here, don’t you think you are missing a space?

also notice that you have a settings parameter but you are making your functions work only for the test_settings dictionary

after change following is the coding:

test_settings={‘theme’:‘dark’,‘notification’:‘enabled’}

def add_setting(setting,key_value):

key=key_value\[0\].lower()

value=key_value\[1\].lower()

if key in setting:

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

else:

     test_settings.update({key:value})

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

def update_setting(settings,key_value):

key=key_value\[0\].lower()

value=key_value\[1\].lower()

if key in settings:

    test_settings.update({key:value})

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

else:

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

def delete_setting(setting,key_value):

key=key_value\[0\].lower()

if key in setting:

    del test_settings\[key\]

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

else:

    return f"Setting not found!"    

def view_settings(test_settings):

str="Current User Settings:\\n"

if len(test_settings)==0:

    return "No settings available"

else:    

    for kv in test_settings.items():

        key=kv\[0\].title()

        value=kv\[1\]

        str+=f"'{key}':'{value}'\\n"

return str 

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

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

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

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

print(view_settings(test_settings))

output

etting ‘theme’ already exists! Cannot add a new setting with this name.
Setting ‘volume’ added with value ‘high’ successfully!
Setting ‘theme’ updated to 'dark’successfully!
Setting not found!
Current User Settings:
‘Theme’:‘dark’
‘Notification’:‘enabled’
‘Volume’:‘high’

still i get following errors

/ running tests
4. add_setting should convert the key to lowercase.
5. add_setting should convert the value to lowercase.
7. add_setting({'theme': 'light'}, ('volume', 'high')) should add a new key-value pair and return the success message Setting 'volume' added with value 'high' successfully!.
8. add_setting should correctly add the given key-value pair to the dictionary.
11. The update_setting function should convert key to lowercase.
12. The update_setting function should convert value to lowercase.
13. update_setting({'theme': 'light'}, ('theme', 'dark')) should update an existing key and return the success message Setting 'theme' updated to 'dark' successfully!.
14. update_setting({'theme': 'light'}, ('volume', 'high')) should return the error message Setting 'volume' does not exist! Cannot update a non-existing setting. when the key doesn't exist.
15. update_setting should correctly update the given key-value pair in the dictionary.
18. delete_setting should convert the key to lowercase.
19. delete_setting({'theme': 'light'}, 'theme') should remove the existing key and return the success message Setting 'theme' deleted successfully!.
21. delete_setting should correctly remove the given key from the dictionary.
24. view_settings should return the message No settings available. if the given dictionary is empty.
25. view_settings should return formatted settings for non-empty dictionary.
26. view_settings should capitalize the first letter of each setting name.
27. view_settings should display the correct results and end with a newline character.
// tests completed
// console output
Setting 'theme' already exists! Cannot add a new setting with this name.
Setting 'volume' added with value 'high' successfully!
Setting 'theme' updated to 'dark'successfully!
Setting not found!
Current User Settings:
'Theme':'dark'
'Notification':'enabled'
'Volume':'high'
1 Like

please repost your code following this guide to improve the readability

When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

test_settings={'theme':'dark','notification':'enabled'}

def add_setting(setting,key_value):
    key=key_value[0].lower()
    value=key_value[1].lower()
    if key in setting:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
    else:
         test_settings.update({key:value})
         return f"Setting '{key}' added with value '{value}' successfully!"
   

def update_setting(settings,key_value):
    key=key_value[0].lower()
    value=key_value[1].lower()
    if key in settings:
        test_settings.update({key:value})
        return f"Setting'{key}' updated to '{value}'successfully!"
    else:
        return f"Setting '{key}' does not exist! cannot update a '{key}':'{value}'non-existing setting."

def delete_setting(setting,key_value


):  
    key=key_value[0].lower()
    if key in setting:
        del test_settings[key]
        return f"Setting '{key}' deleted successfully!."
    else:
        return f"Setting '{key}' not found!"    

    

def view_settings(test_settings):
    str="Current User Settings:\n"
    if len(test_settings)==0:
        return "No settings available"
    else:    
        for kv in test_settings.items():
            key=kv[0].title()
            value=kv[1]
            str+=f"'{key}':'{value}'\n"
    return str 
print(add_setting({'theme':'light'},('THEME','dark')))  
print(add_setting({'theme':'light'},('Volume','high')))
print(update_setting({'theme': 'light'}, ('theme', 'dark')))
print(delete_setting({'theme': 'light'}, 'theme'))
print(view_settings(test_settings))
1 Like

tell me where i am wrong

you still have functions that work only with thtest_settings dictionary, because you are not always using the function parameters

and then check your spacing

def add_setting(setting,key_value):

key=key_value\[0\].lower()

value=key_value\[1\].lower()

if key in setting:

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

else:

     test_settings.update({key:value})

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

what is wrong ??

you have post again your code in a format that is difficult to read

which part is not clear? you are using test_settings inside your functions, your functions are not reusable, so they fail the tests

its showing errors to convert key and value to lower case , that i am already doing

test_settings={'theme':'dark','notification':'enabled'}

def add_setting(setting,key_value):
    key=key_value[0].lower()
    value=key_value[1].lower()
    if key in setting:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
    else:
         test_settings.update({key:value})
         return f"Setting '{key}' added with value '{value}' successfully!"
 

def update_setting(settings,key_value):
    key=key_value[0].lower()
    value=key_value[1].lower()
    if key in settings:
        test_settings.update({key:value})
        return f"Setting'{key}' updated to '{value}'successfully!"
    else:
        return f"Setting '{key}' does not exist! cannot update a '{key}':'{value}'non-existing setting."

def delete_setting(setting,key_value):  
    key=key_value.lower()
    if key in setting:
        del test_settings[key]
        return f"Setting '{key}' deleted successfully!."
    else:
        return f"Setting '{key}' not found!"    

    

def view_settings(test_settings):
    str="Current User Settings:\n"
    if len(test_settings)==0:
        return "No settings available"
    else:    
        for kv in test_settings.items():
            key=kv[0].title()
            value=kv[1]
            str+=f"'{key}':'{value}'\n"
    return str 
print(add_setting({'theme': 'light'},('THEME','dark')))  
print(add_setting({'theme': 'light'},('Volume','high')))
print(update_setting({'theme': 'light'}, ('theme', 'dark')))
print(delete_setting({'theme': 'light'}, 'theme'))
print(view_settings(test_settings))

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

convert key and value to lower case message is coming which already done in the code but still its showing same errors

test_settings={'theme':'light','notification':'enabled'}

def add_setting(settings,key_value):
    key=key_value[0].lower()
    value=key_value[1].lower()
    if key in settings:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
    else:
         test_settings.update({key:value})
         return f"Setting '{key}' added with value '{value}' successfully!"
 

def update_setting(settings,key_value):
    key=key_value[0].lower()
    value=key_value[1].lower()
    if key in settings:
        test_settings.update({key:value})
        return f"Setting'{key}' updated to '{value}'successfully!"
    else:
        return f"Setting '{key}' does not exist! cannot update a '{key}':'{value}'non-existing setting."

def delete_setting(settings,key_value):  
    key=key_value.lower()
    if key in settings:
        del settings[key]
        return f"Setting '{key}' deleted successfully!"
    else:
        return f"Setting '{key}' not found!"        

def view_settings(settings):
    str="Current User Settings:\n"
    if len(settings)==0:
        return "No settings available"
    else:    
        for kv in settings.items():
            key=kv[0].title()
            value=kv[1]
            str+=f"'{key}':'{value}'\n"
    return str 
print(add_setting({'theme': 'light'},('THEME','dark')))  
print(add_setting({'theme': 'light'},('Volume','high')))
print(update_setting({'theme': 'light'}, ('theme', 'dark')))
print(delete_setting({'theme': 'light'}, 'theme'))
print(view_settings(test_settings))

now its working on parameter settings only not on test_settings but still not done

Here are some debugging steps you can follow. Focus on one test at a time.

  1. add_setting should convert the key to lowercase.
  1. Are there any errors or messages in the console?
  2. What is the requirement of test?
  3. Check the related User Story and ensure it’s followed precisely.
  4. What line of code implements this?
  5. What is the result of the code and does it match the requirement? (Write the value of a variable to the console at that point in the code if needed.)

If this does not help you solve the problem, please reply with answers to these questions.

you are still using test_settings a lot, until you stop it will not work

is the dictionary you are passing to add_settings the same as test_settings? and yet, in your function, you are updating the global test_settings variable rather than the dictionary you passed in your function call. does that make sense? you are doing the same thing in your other functions, too.

**THE many problem is that you are using global variable ‘**test_settings’ **instead of function parameter ‘**settings’ .

My code below only focus logic but maybe may not pass the unit test because you didn’t include project info

So double check info or provide the whore info or the test which is failing

code removed by moderator

hi @isaacc265

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

after doing changes i am still getting errors

test_settings={‘theme’:‘light’,‘notification’:‘enabled’}

def add_setting(settings,key_value):

key=key_value\[0\].lower()

value=key_value\[1\].lower()

if key in settings:

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

else:

     settings\[key\]=value

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

def update_setting(settings,key_value):

key=key_value\[0\].lower()

value=key_value\[1\].lower()

if key in settings:

    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_value):

key=key_value.lower()

if key in settings:

    del settings\[key\]

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

else:

    return f"Setting not found!"        

def view_settings(settings):

str="Current User Settings:\\n"

if len(settings)==0:

    return "No settings available"

else:    

    for kv in settings.items():

        key=kv\[0\].title()

        value=kv\[1\]

        str+=f"'{key}':'{value}'\\n"

return str 

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

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

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

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

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

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

print(view_settings({‘theme’: ‘dark’, ‘notifications’: ‘enabled’, ‘volume’: ‘high’}))

print(view_settings({}))

still i am getting errors

13. update_setting({'theme': 'light'}, ('theme', 'dark')) should update an existing key and return the success message Setting 'theme' updated to 'dark' successfully!.
14. update_setting({'theme': 'light'}, ('volume', 'high')) should return the error message Setting 'volume' does not exist! Cannot update a non-existing setting. when the key doesn't exist.
24. view_settings should return the message No settings available. if the given dictionary is empty.
25. view_settings should return formatted settings for non-empty dictionary.
26. view_settings should capitalize the first letter of each setting name.
27. view_settings should display the correct results and end with a newline character.
// tests completed
// console output
Setting 'theme' already exists! Cannot add a new setting with this name.
Setting 'volume' added with value 'high' successfully!
Setting'theme' updated to 'dark' successfully!
Setting 'volume' does not exist! cannot update a non-existing setting.
Setting 'theme' deleted successfully!
Setting not found!
Current User Settings:
'Theme':'dark'
'Notifications':'enabled'
'Volume':'high'

No settings available

please post again your code properly formatted, we can’t check your code when it’s not properly formatted