Build a User Configuration Manager - Build a User Configuration Manager

Tell us what’s happening:

The check 27 don’t pass despite the fact the output is acording to the result demanded. Please can you give me any hint about what’s the problem?

Your code so far

def add_setting(param_d, param_t):

	param_tlow = tuple([item.lower() if isinstance(item, str) else item for item in param_t ])

	if param_tlow[0] in param_d.keys() and param_tlow[1] != param_d[param_tlow[0]]:
		return f"Setting '{param_tlow[0]}' already exists! Cannot add a new setting with this name."

	else:
		param_d[param_tlow[0]] = param_tlow[1]

	return f"Setting '{param_tlow[0]}' added with value '{param_tlow[1]}' successfully!"


def update_setting(param_d, param_t):

	param_tlow = tuple([item.lower() if isinstance(item, str) else item for item in param_t ])

	if param_tlow[0] in param_d.keys():
		param_d[param_tlow[0]] = param_tlow[1]
		return f"Setting '{param_tlow[0]}' updated to '{param_tlow[1]}' successfully!"

	else:
		return f"Setting '{param_tlow[0]}' does not exist! Cannot update a non-existing setting."


def delete_setting(param_d, param_k):

	param_klow = param_k.lower()

	if param_klow in param_d:
		del param_d[param_klow]
		return f"Setting '{param_klow}' deleted successfully!"

	else:
		return f"Setting not found!"


def view_settings(param_d):
	if not param_d:
		return f"No settings available."
	elif param_d:
		display = f"Current User Settings:"
		for k, v in param_d.items():
			display += f"\n{k.title() if isinstance(k, str) else k }: {param_d[k].lower()if isinstance(param_d[k], str) else param_d[k]}"

		return display+'\n'

test_settings = {'theme': 'dark', 'notifications': 'enabled', 'volume': 'high'}

print(view_settings(test_settings))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

What instructions are given for formatting the output? The values specifically?

  • 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:
Current User Settings:
Theme: dark
Notifications: enabled
Volume: high

As you can see, the output of my script is the same as the output the instructions require.

Based in the instructions what should this return?

view_settings({'theme': 'Dark', 'notifications': 'Enabled', 'volume': 'High'})

with the key capitalized

The key should be capitalized. What about the value? In the example given, all of the values are given in lowercase, so the output is lowercase.

with the key capitalized

The instructions say the key should be capitalized. It doesn’t say anything specific about the values.

The values are lower cased in the example solution. And the instructions don’t say anything about values casing.

But what confuses me the most is that the sample solution is the same as my script’s solution. I don’t understand what’s the error is!

Exactly. Are you doing anything to the values casing?

You never see an example of an input with a capital letter, so you don’t have an example of how to handle the values.

If the instructions wanted you to do anything with the values, it would say so. Just as it does with the keys.

Thank you, you helped me a lot!

1 Like