Build a User Configuration Manager - Build a User Configuration Manager

Tell us what’s happening:

  1. view_settings should display the correct results and end with a newline character.
    // tests completed
    // console output
    Current User Settings:
    Theme: dark
    Notifications: enabled
    Volume: high

Your code so far

def add_setting(settings_dict, setting_tuple):
    """
    向设置字典中添加新的键值对
    """
    # 将键和值转换为小写
    key = setting_tuple[0].lower()
    value = setting_tuple[1].lower()
    
    # 检查键是否已存在
    if key in settings_dict:
        return f"Setting '{key}' already exists! Cannot add a new setting with this name."
    else:
        # 添加新设置
        settings_dict[key] = value
        return f"Setting '{key}' added with value '{value}' successfully!"


def update_setting(settings_dict, setting_tuple):
    """
    更新设置字典中已存在的键值对
    """
    # 将键和值转换为小写
    key = setting_tuple[0].lower()
    value = setting_tuple[1].lower()
    
    # 检查键是否存在
    if key in settings_dict:
        # 更新设置
        settings_dict[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):
    """
    从设置字典中删除指定的键值对
    """
    # 将键转换为小写
    key_lower = key.lower()
    
    # 检查键是否存在
    if key_lower in settings_dict:
        # 删除设置
        del settings_dict[key_lower]
        return f"Setting '{key_lower}' deleted successfully!"
    else:
        return "Setting not found!"


def view_settings(settings_dict):
    """
    查看当前所有设置
    """
    # 检查字典是否为空
    if not settings_dict:
        return "No settings available."
    
    # 构建显示字符串
    result = "Current User Settings:"
    for key, value in settings_dict.items():
        # 将键的首字母大写
        key_capitalized = key.capitalize()
        result += f"\n{key_capitalized}: {value}"
    
    return result


# 测试用的设置字典
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/143.0.0.0 Safari/537.36 Edg/143.0.0.0

Challenge Information:

Build a User Configuration Manager - Build a User Configuration Manager

Welcome to the forum @witt0725

Please describe what is happening in your own words.

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

Happy coding

你的函数输出是否以换行符(“\n”)结尾?
Does your function output end with a newline (“\n”)?