import random

# 成语库
idioms = [
    "一帆风顺", "二龙戏珠", "三阳开泰", "四季平安", "五福临门",
    "六六大顺", "七星高照", "八方来财", "九九同心", "十全十美",
    "万事如意", "心想事成", "前程似锦", "步步高升", "蒸蒸日上",
    "春暖花开", "山清水秀", "风调雨顺", "国泰民安", "合家欢乐"
]

# 获取最后一个字
def get_last_char(word):
    return word[-1]

# 获取第一个字
def get_first_char(word):
    return word[0]

print("===== 成语接龙游戏 =====")
start_word = random.choice(idioms)
print(f"开局成语：{start_word}")
last_char = get_last_char(start_word)

while True:
    user_input = input(f"请接以【{last_char}】开头的成语：")
    # 判断开头字是否匹配
    if user_input not in idioms:
        print("这个成语不在词库中，重新来！")
        continue
    if get_first_char(user_input) != last_char:
        print("开头字不对，接龙失败！游戏结束")
        break
    print(f"接上啦！你的成语：{user_input}")
    last_char = get_last_char(user_input)