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
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.
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’)))
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
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!.