Build a user configuration manager

Im on the last challenges 25, and 27, everything appears to be outputting correctly, does anyone have any details as to what these challenges are actually expecting because its sort of vague and to me it looks like its outputting perfectly.

challenges:

  • Failed:25. view_settings should return formatted settings for non-empty dictionary.

  • Failed:27. view_settings should display the correct results and end with a newline character.

# a test dictionary of a users settings
test_settings = {
    'theme': 'light',
    'notifications': 'enabled',
    'volume': 'high'
}

# a list of available settings
setting_list = ('theme', 'notifications', 'volume')

# adding a new user setting 
def add_setting(test_settings, setting_new):

# convert the key and value to lowercase
    key, value = setting_new
    key = key.lower()
    value = value.lower()

# check if the setting already exists and perform action
    if key in test_settings:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
    
    else:
        test_settings[key] = value
        return f"Setting '{key}' added with value '{value}' successfully!"

# updating user setting
def update_setting(test_settings, setting_new):

# convert the key and value to lowercase
    key, value = setting_new
    key = key.lower()
    value = value.lower()

# check if the setting exists and perform action
    if key in test_settings:
        test_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."
   
#delete user setting
def delete_setting(test_settings, setting_new):

# convert the key and value to lowercase
    key = setting_new
    key = key.lower()

# check if the setting exists and perform action
    if key in test_settings:
        del test_settings[key]
        return f"Setting '{key}' deleted successfully!"
    else:
        return f"Setting not found!"
    
#view user settings
def view_settings(test_settings):

# format contents of non-empty dictionary
    if not test_settings:
        return f"No settings available."
    else:
        display_settings = ("Current user settings:""\n") 
        for key, value in test_settings.items():
            setting = f"{key.capitalize()}: {value.lower()}" + "\n"
            display_settings += setting
        return display_settings
               
# add_setting test
add_setting({'theme': 'light'}, ('THEME', 'dark'))
# update_setting test
update_setting({'theme': 'light'}, ('theme', 'dark'))
# delete_setting test
delete_setting({'theme': 'light'}, 'theme')
# view_setting test
view_settings(test_settings)
print(repr(view_settings(test_settings)))
print(view_settings(test_settings))

the console output looks like this:

'Current user settings:\nTheme: light\nNotifications: enabled\nVolume: high\n'
Current user settings:
Theme: light
Notifications: enabled
Volume: high

please always remember to link the challenge you are asking for help with, it makes helping you much easier

anyway, please see user story 8, specifically the second bullet point

1 Like

will do that next time, thanks.
LOL omg i didnt even remember about the instructions there, im always complaining theres not enough details and its my own fault.

that did resolve 25 easily enough, now its just the final one that is failing.

okay, well its rather silly and seems like a bug to me but all i had to do for the last step was remove “.lower” from after the “value”. I dont really understand why that would fail since the output is exactly the same but id just like to say thank you for your help and time.
heres a copy of what i ended up with.

#view user settings
def view_settings(test_settings):

# format contents of non-empty dictionary
    if not test_settings:
        return f"No settings available."
    else:
        display_settings = ("Current User Settings:""\n") 
        for key, value in test_settings.items():
            setting = f"{key.capitalize()}: {value}" + "\n"
            display_settings += setting
        return display_settings

1 Like

if it changes or not, it depends on what the input is, and it looks like the function is being tested under the hood with something for which that makes a difference

1 Like

yea i kind of thought of that after, its proably testing something im not thinking of, i know theres so many ways to do things, maybe its just making sure i wasnt doing it in some round about way like i often do lmao :joy:

I came here looking for help with the same problem, which was because I, too, was calling .lower() on the value string.

I don’t know how to verify my theory, but presumably the test code tests view_settings() with a dictionary that has one or more capital letters in the value strings, and expects any capitalization to be preserved in the returned string.

This is a bit of a strange gotcha, since everywhere else the code is supposed to smash case.

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

In order to pass a dictionary to the functions, I wrote like this

removed by moderator

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.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.