python编写成语接龙

接收从键盘输入成语,并连接成长龙;检查成语收尾字

tmp=""
i=1
while True:
    idiom = input("请输入第" + str(i) + "个成语:")
    if idiom == "":
        print("Game Over!")
        print(tmp)
        break
    else:
        if tmp == "":
            tmp=idiom
            i+=1
        elif (tmp[-1] == idiom[0] and tmp.find(idiom) == -1):
            tmp += " " + idiom
            i+=1
        else:
            print("您输入的成语不符合接龙规则,请重新输入!")
    print(tmp)

你可能感兴趣的:(python)