python实现成语接龙??

群里面玩的成语接龙很嗨,想到了之前的一个顶俩的项目,自己搞一个陷害QQ小冰的程序吧。

扩展包

pypinyin
扩展包地址传送门

成语词典数据来源

https://github.com/mozillazg/python-pinyin
嫌GitHub慢的也可去
http://ggalaxy.top/file/idiom.json自取

具体代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import json
import pypinyin

file = open("idiom.json","rb")
file_json = json.load(file)
l = len(file_json)
while(1):
s = input("目前要开始的字符:(输入exit退出):")
if(s == ""):
continue
if(s == "exit"):
break
pinyin1 = pypinyin.pinyin(s)[0][0]
print(pinyin1)
#转为拼音
e = input("想要结尾的字符,不要求的输入nothing:")
if e == "" or e =="nothing":
for i in range(l):
ll = len(file_json[i]["word"])
if(file_json[i]["pinyin"].split(" ")[0] == pinyin1):
print("-----------------------------------------------------------------------------------------------------")
print(file_json[i]["word"],end = "")
print(" ||拼音:",end = "")
print(file_json[i]["pinyin"],end = "")
print(" ||释意:",end = "")
print(file_json[i]["derivation"])
else:
for i in range(l):
ll = len(file_json[i]["word"])
if(file_json[i]["pinyin"].split(" ")[0] == pinyin1 and file_json[i]["word"][ll-1] == e):
print("--------------------------------------------------------------------------------------------------------")
print(file_json[i]["word"],end = "")
print(" ||拼音:",end = "")
print(file_json[i]["pinyin"],end = "")
print(" ||释意:",end = "")
print(file_json[i]["derivation"])
print(file_json[9356]["derivation"])



调戏

在这里插入图片描述

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2015-2023 galaxy
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信