I can’t get past step 7 or steps 25-27, please help
Please post your current code and a link to the lab/project. Thanks
How do I post the code
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',
'notifications': 'enabled',
}
def add_setting(settings, key_value_pair):
key, value = [item.lower() for item in key_value_pair]
if key in settings.keys():
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}' successfully."
def update_setting(settings, key_value_pair):
key, value = [item.lower() for item in key_value_pair]
if key in settings.keys():
settings.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."
def delete_setting(settings, dictionary_key):
key = dictionary_key.lower()
if key in settings.keys():
settings.pop(key, 'error')
return f"Setting '{key}' deleted successfully!"
else:
return "Setting not found!"
def view_settings(settings):
if not settings:
return "No settings available."
else:
open_dictionary = "Current User Settings:"
for key, value in settings.items():
display_key = key.capatilize()
open_dictionary += f"\n{display_key}: {value}"
return open_dictionary
#print(add_setting({'theme': 'light'}, ('volume', 'high')))
#print(update_setting(test_settings, item))
#print(delete_setting(test_settings, key))
#print(view_settings(test_settings))
#print(test_settings)
And a link to the lab/project?
Ok, we’re getting somewhere now. How did you get stuck in your debugging?
Here are some troubleshooting steps you can follow. Focus on one test at a time:
- Are there any errors or messages in the console?
- What is the requirement of the first failing test?
- Check the related User Story and ensure it’s followed precisely.
- What line of code implements this?
- 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.
For 7, it doesn’t add the new dictionary entries to the dictionary, but I don’t see why my code wouldn’t allow that. For 25-27 I just figured out that I spelled capitalize wrong.
Did you try running that test case yourself? I found a difference in the expected output string and yours.
Yeah I used the given dictionary in step 7 and tried to run it in the code and it didn’t work
I tested it again it worked for my test_settings dictionary but step 7 still won’t pass.
How did you test?
Can you show your input and output and how it’s the same or different than the expected output?
It ended up being the same, it turns out I just forgot to write the full sentence in the return value for the add settings function.
Yup, I was hoping you’d see than if you manually ran the test case.
