Build a User Configuration Manager - Build a User Configuration Manager

Tell us what’s happening:

I couldn’t get pass test 4 Here is my code:

test_settings = {“Name”: “Messi”,“Theme”:“light”, “Background”: “Messi”, “Notifications”: True,
“Volume”: “Low” }

def add_setting (settings , key_pair):
#my problem starts Here
m = test_settings
update = tuple(m.lower() if isinstance(m,str) else m for m in key_pair)

key = update [0]
value = update [1]


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

Your code so far




test_settings = {"Name": "Messi","Theme":"light", "Background": "Messi", "Notifications": True,
"Volume": "Low" }







def add_setting (settings , key_pair):
    #my problem starts Here
    m = test_settings
    update = tuple(m.lower() if isinstance(m,str) else m for m in key_pair)

    key = update [0]
    value = update [1]


    if key in m:
        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!"


def update_setting(update, new_pair):
    new_update = tuple(m.lower() if isinstance(m,str) else m for m in new_pair)
    if key in update:
        return "Setting '\{key}\' updated to '\{value}\'"
print(add_setting(test_settings,("r""Ronaldo")))
#Were the Delete happens
def delete_setting (setting, change):
    pass

def view_settings(setting):
    pass


Your browser information:

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

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

Hi @Question_3 ,

  1. You should define a function named add_setting with two parameters representing a dictionary of settings and a tuple containing a key-value pair

You are not passing a tuple as the second argument in your function call.

Happy coding!

Is the problem with my function or my print call?

Tell us what’s happening:

Here is my code and I am failing to get step 6 and 7 and the same time here is my code:

test_settings = {“Name”: “Messi”,“Theme”:“light”, “Background”: “Messi”, “Notifications”: True,
“Volume”: “Low” }

def add_setting (settings , key_pair):
#my problem starts Here
m = test_settings
update = tuple(m.lower() if isinstance(m,str) else m for m in key_pair)

key = update [0]
value = update [1]
settings[key] = value
test_settings [str(key)] = value
if key in m

Your code so far




test_settings = {"Name": "Messi","Theme":"light", "Background": "Messi", "Notifications": True,
"Volume": "Low" }







def add_setting (settings , key_pair):
    #my problem starts Here
    m = test_settings
    update = tuple(m.lower() if isinstance(m,str) else m for m in key_pair)

    key = update [0]
    value = update [1]
    settings[key] = value
    test_settings [str(key)] = value
    if key in m:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
        # step 7
    if not key in m:
        settings[key] = value
        return f"Setting '{key}' added with value '{value}' successfully!" 

def update_setting(update, new_pair):
    key, value = [item.lower() for item in key_value_pair]
    if key in update.keys():
        return "Setting '{key}' updated to '{value}'"
print(add_setting({'theme': 'light'}, ('volume', 'high')))
#Were the Delete happens
def delete_setting (setting, change):
    pass

def view_settings(setting):
    pass


Your browser information:

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

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

The thing I notice is when I remove test_settings [str(key)] = value I pass step 7 but not step 6 and when I bring back test_settings[str(key)] I pass step 6 but not 7

Please do not create duplicate topics for the same challenge/project question(s). If you need more help then respond back to the original topic you created with your follow up questions and/or your updated code and question.
This duplicate topic has been unlisted.

Thank you.




test_settings = {"Name": "Messi","Theme":"light", "Background": "Messi", "Notifications": True,
"Volume": "Low" }







def add_setting (settings , key_pair):
    #my problem starts Here
    m = test_settings
    
    
    key = key_pair [0]. lower()
    value = key_pair [1]. lower()

    test_settings [str(key)] = value
    if key in settings:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
        # step 7
        settings [key] = value
    else:
        settings [key] = value
        return f"Setting '{key}' added with value '{value}' successfully!" 

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


def update_setting(update, new_pair):
    key, value = [item.lower() for item in key_value_pair]
    key = update [0]. lower()
    if key in update.keys():
        return "Setting '{key}' updated to '{value}'"
#Were the Delete happens
def delete_setting (setting, change):
    pass

def view_settings(setting):
    pass


It says that my code raised and error before any test could be run and I don’t know what that error is and I don’t see any error

How are you testing your functions? I don’t see a function call in your code.

And look for the error in your browser’s console, not the fCC console.

I don’t have an error that I can see. I only see a light bulb and below it it says: Your code raised an error before any tests could run. Please fix it and try again. I tested add_settings when I wrote this code: print(add_setting({‘theme’: ‘light’}, (‘volume’, ‘high’)))




test_settings = {"Name": "Messi","Theme":"light", "Background": "Messi", "Notifications": True,
"Volume": "Low" }







def add_setting (settings , key_pair):
    #my problem starts Here
    m = test_settings
    
    
    key = key_pair [0]. lower()
    value = key_pair [1]. lower()

    test_settings [str(key)] = value
    if key in settings:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
        # step 7
        settings [key] = value
    else:
        settings [key] = value
        return f"Setting '{key}' added with value '{value}' successfully!" 

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


def update_setting(update, new_pair):

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

    if key in update:
        return "Setting '{key}' updated to '{value}'"
print(update_setting("He","He"))
#Were the Delete happens
def delete_setting (setting, change):
    pass

def view_settings(setting):
    pass


I think I fixed it but know it says for me to convert update_setting to lowercase which I am pretty sure I am doing

I have a question don’t you just have to type in . lower after a variable to convert it to lowercase?

lower() is a string method you can apply to a variable with a string value and, yes, that would convert that variable’s value to a lowercase string.

Python String lower() Method

I have another question when I did key= key_pair[0]. lower() it made it into lowercase but when I did key = new_pair [0]. lower() I didn’t pass the test of converting key to lowercase in the update function

That function is only returning something if the key is in update.

What is the difference between key = key_pair [0]. lower and key = new_pair[0]. lower()? I am basically using the same code putting it in a different function and modifying it.

def add_setting (settings , key_pair):
    
    m = test_settings
    
    
    key = key_pair [0]. lower()
    value = key_pair [1]. lower()

    
    if key in settings:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
        # step 7
        settings [key] = value
    else:
        settings [key] = value
        return f"Setting '{key}' added with value '{value}' successfully!" 

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

def update_setting(update, new_pair):

    key = new_pair[0]. lower()
    value = new_pair [1]. lower()
    
    if key in update.keys():
        return f"Setting '{key}' updated to '{value}'successfully!"
print (update_setting({'theme': 'light'}, ('theme', 'dark')))




test_settings = {
"Name": "Messi",
"Theme":"light", "Background":"Messi", 
"Notifications": "enabled",
"Volume": "Low" 
}







def add_setting (settings , key_pair):    


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

    
    if key in settings:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
        # step 7
        
    else:
        settings [key] = value    
        return f"Setting '{key}' added with value '{value}' successfully!" 

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


def update_setting(updates, new_pair):

    key = new_pair[0].lower()
    value = new_pair [1]. lower()
    
    if key in updates:
        updates[key] = value
        updates.update({key :  value})
        
        return f"Setting '{key}' updated to '{value}'successfully!"

    else:   
       return f"Setting '{key}' does not exist! Cannot update a non-existing setting."
    
print (update_setting({'theme': 'light'}, ('theme', 'dark')))



#Were the Delete happens
def delete_setting (setting, change):

    key = change[0].lower()
    
    if setting == {}:
        return "Settings not found"

    if key in setting:
        del setting [key]
        setting [key] = key
        return f"Setting '{key}' deleted successfully!"

    else:
        return "Setting not found"
    

print(delete_setting(test_settings,"h"))


def view_settings(setting):
    
    if setting == {}:
        return "No settings available."


    else:
        first = "Current User Settings:\n"
        for s in setting.items():
            key = s[0]. title()
            value = s[1]
            
        
            first += f"{key} : {value}\n"
        return first
        
            

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


My problem is that I am not passing test 13 and I think I have updated the key but it is still saying: update_setting({'theme': 'light'}, ('theme', 'dark')) should update an existing key and return the success message Setting 'theme' updated to 'dark' successfully!.

Look at the spacing in the message you are returning.




test_settings = {
"Name": "Messi",
"Theme":"light", "Background":"Messi", 
"Notifications": "enabled",
"Volume": "Low" 
}







def add_setting (settings , key_pair):    


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

    
    if key in settings:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
        # step 7
        
    else:
        settings [key] = value    
        return f"Setting '{key}' added with value '{value}' successfully!" 

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


def update_setting(updates, new_pair):

    key = new_pair[0].lower()
    value = new_pair [1]. lower()
    
    if key in updates:
        updates[key] = value
        
        
        return f"Setting '{key}' updated to '{value}' successfully!"

    else:   
       return f"Setting '{key}' does not exist! Cannot update a non-existing setting."
    
print (update_setting({'theme': 'light'}, ('theme', 'dark')))



#Were the Delete happens
def delete_setting (setting, change):

    key = change[0].lower()
    #setting[key] = key

    

    if key in setting:
        del setting [key]
        setting [key] = key
        return f"Setting '{key}' deleted successfully!"
    else:
        return "Setting not found!"
    

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


def view_settings(setting):
    
    if setting == {}:
        return "No settings available."


    else:
        first = "Current User Settings:\n"
        for s in setting.items():
            key = s[0]. title()
            value = s[1]
            
        
            first += f"{key}: {value}\n"
        return first
        
            

print(view_settings({"theme": 'dark', 'notifications': 'enabled', 'volume': 'high'}))


Now I am having problems with test 18, 19,21.

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.

I am pretty sure I did all of the things I was suppose to do

What is the value of change[0]?

Is setting a list? What method should you use to delete a key/value pair from setting?

What is your code doing here?