求Python代码,简单明了

img


heihua_dict = {"xswl": "笑死我了", "dbq": "对不起", "cxk": "蔡徐坤", "yyds": "永远的神"}
while True:
    str1 = input("请输入带有黑话的句子以及黑话,用英文逗号(,)分隔:")
    str_list = str1.split(",")
    # 判断用户输入是否正确,若正确列表长度会为2
    if len(str_list) == 2:
        # 原话
        temp_str1 = str_list[0]
        # 黑话
        temp_str2 = str_list[1]
        # 获得真实黑话
        new_str = heihua_dict[temp_str2]
        # 替换
        result = temp_str1.replace(temp_str2, new_str)
        print(result)
        break
    else:
        print("输入有误或不存在改黑话!!")