Tell us what’s happening:
I am unable to pass the first test “You should create a dictionary called test_settings”. All other tests run fine. Please help me where I am wrong.
Your code so far
def add_setting(settings: dict, new_pair: tuple) -> str:
if not isinstance(new_pair, tuple) or len(new_pair) != 2:
return "Error: Input must be a tuple of (key, value)."
key = str(new_pair[0]).lower()
value = str(new_pair[1]).lower()
if key in settings:
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 '{value}' successfully!"
def update_setting(settings: dict, update_pair: tuple) -> str:
if not isinstance(update_pair, tuple) or len(update_pair) != 2:
return "Error: Input must be a tuple of (key, value)."
key = str(update_pair[0]).lower()
value = str(update_pair[1]).lower()
if key in settings:
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."
def delete_setting(settings: dict, key_to_delete: str) -> str:
key = str(key_to_delete).lower()
if key in settings:
del settings[key]
return f"Setting '{key}' deleted successfully!"
else:
return "Setting not found!"
def view_settings(settings: dict) -> str:
if not settings:
return "No settings available."
output = "Current User Settings:"
for key, value in settings.items():
display_key = key.capitalize()
output += f"\n{display_key}: {value}"
return output+"\n"
test_settings = {
'theme': 'dark',
'notifications': 'enabled',
'volume': 'high',
}
print("--- Initial State ---")
print(view_settings(test_settings))
print("-" * 25)
print("\n--- Test 1: Adding Initial Settings ---")
print(add_setting(test_settings, ('ThEmE', 'dArK')))
print(add_setting(test_settings, ('nOTIFICATIONS', 'eNaBLED')))
print(add_setting(test_settings, ('volume', 'High')))
print("\n[Current Settings]")
print(view_settings(test_settings))
print("\n--- Test 2: Attempting to Add Existing Key ---")
print(add_setting(test_settings, ('theme', 'light'))) # Should fail
print("\n[Current Settings]")
print(view_settings(test_settings)) # Should still be dark
print("\n--- Test 3: Updating Existing Key ---")
print(update_setting(test_settings, ('notifications', 'disabled')))
print(update_setting(test_settings, ('VOLUME', 'medium')))
print("\n[Current Settings]")
print(view_settings(test_settings))
print("\n--- Test 4: Attempting to Update Non-Existing Key ---")
print(update_setting(test_settings, ('language', 'spanish')))
print("\n[Current Settings]")
print(view_settings(test_settings))
print("\n--- Test 5: Deleting Keys ---")
print(delete_setting(test_settings, 'theme'))
print(delete_setting(test_settings, 'NOTIFICATIONS'))
print("\n[Current Settings]")
print(view_settings(test_settings))
print("\n--- Test 6: Attempting to Delete Non-Existing Key ---")
print(delete_setting(test_settings, 'theme'))
print("\n--- Test 7: Viewing Empty Settings ---")
delete_setting(test_settings, 'volume')
print(view_settings(test_settings))
print("-" * 25)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Challenge Information:
Build a User Configuration Manager - Build a User Configuration Manager