This project is part of the freeCodeCamp Python Certification.
It implements a simple user configuration manager that allows adding, updating, deleting, and viewing settings stored in a dictionary.
- Add a new setting (key-value pair)
- Update an existing setting
- Delete a setting
- View all current settings
- Python 3
-
You should define a function named
add_settingwith two parameters representing a dictionary of settings and a tuple containing a key-value pair -
add_settingfunction should:- Convert the key and value to lowercase.
- If the key setting exists, return
Setting '[key]' already exists! Cannot add a new setting with this name. - If the key setting doesn't exist, add the key-value pair to the given dictionary of settings and return
Setting '[key]' added with value '[value]' successfully!. - The messages returned should have the key and value in lowercase.
-
You should define a function named
update_settingwith two parameters representing a dictionary of settings and a tuple containing a key-value pair. -
update_settingfunction should:- Convert the key and value to lowercase.
- If the key setting exists, update its value in the given dictionary of settings and return:
Setting '[key]' updated to '[value]' successfully! - If the key setting doesn't exist, return
Setting '[key]' does not exist! Cannot update a non-existing setting. - The messages returned should have the key and value in lowercase.
-
You should define a function named
delete_settingwith two parameters representing a dictionary of settings and a key. -
delete_settingfunction should:- Convert the key passed to lowercase.
- If the key setting exists, remove the key-value pair from the given dictionary of settings and return
Setting '[key]' deleted successfully! - If the key setting does not exist, return
Setting not found! - The messages returned should have the key in lowercase.
-
You should define a function named
view_settingswith one parameter representing a dictionary of settings. -
view_settingsfunction should:- Return
No settings available.if the given dictionary of settings is empty. - If the dictionary contains any settings, return a string displaying the settings. The string should start with
Current User Settings:followed by the key-value pairs, each on a new line and with the key capitalized. For example,view_settings({'theme': 'dark', 'notifications': 'enabled', 'volume': 'high'})should return:
- Return
Current User Settings:
Theme: dark
Notifications: enabled
Volume: high
- For testing the code, you should create a dictionary named
test_settingsto store some user configuration preferences.
Example test cases are included as commented lines at the bottom of main.py.
Uncomment them to run and see the output.
- This project was developed to meet the certification requirements.
- The implementation focuses on correctness and clarity rather than extended functionality.