[Python] 纯文本查看 复制代码 #!/usr/bin/env python
# -*- coding: utf-8 -*-
# import itchat
import csv
import random
words = {}
with open(r'world.csv', 'r') as f:
reader = csv.reader(f)
for row in reader:
words[row[0]] = row[3:]
word = random.choice(list(words))
print('开始接龙:' + word)
print('【解释】' + words[word][0])
print('【出处】' + words[word][1])
print('【拼音】' + words[word][2])
print('【首字音】' + words[word][3])
print('【尾字音】' + words[word][4])
ing = 0 # 当前关数
end = 2 # 总关数
tip = 13 # 提示的次数
already = [word] # 已经回答过的成语
quit = 1
while quit:
ing += 1
print('开始第{}场游戏,总{}场'.format(ing, end))
while True:
u_word = raw_input('【{}】,输入你的成语:'.format(word))
if u_word in list(words.keys()):
if words[u_word][3] != words[word][-1]:
print('你输入的【{}】这个成语不符合接龙,你需要接龙的首字拼音为【{}】'.format(u_word, words[already[word]][4]))
continue
elif u_word in already:
print('接龙成语不能重复哦!你需要接龙的首字拼音为【{}】'.format(words[already[word]][4]))
continue
elif words[u_word][3] == words[word][-1]:
expound = '【解释】' + words[u_word][0] + '\n'
source = '【出处】' + words[u_word][1] + '\n'
success = '【{}】接龙成功'.format(u_word) + '\n'
print(expound + source + success)
already.append(u_word)
word = u_word
break
if u_word == '不会':
answer = list(words.keys())[[i[3] for i in list(words.values())].index(words[word][-1])]
over = '此轮结束,答案【{}】'.format(answer) + '\n'
expound = '【解释】' + words[answer][0] + '\n'
source = '【出处】' + words[answer][1] + '\n'
print(over + expound + source)
already.append(answer)
word = words[answer]
quit = 0
break
if u_word == "提示" and tip > 0:
tip -= 1
answer = list(words.keys())[[i[3] for i in list(words.values())].index(words[word][-1])]
print('提示:你可以答【{}】,你还剩下{}次提示机会'.format(answer, tip) + '\n')
continue
if u_word == "提示" and tip <= 0:
print('你没有提示机会哦!' + '\n')
continue
if u_word == "666":
tip += 10
print('恭喜你找到隐藏福利,提示机会+10次,你还有{}次提示'.format(tip) + '\n')
continue
if u_word not in list(words.keys()):
print('【{}】这不是成语哦!你需要接龙的首字拼音为【{}】'.format(u_word, words[word][4]))
continue
if ing >= end:
print('游戏结束!获得10000W')
con = raw_input('是否继续游戏?(是/否):')
if con == "是":
word = random.choice(list(words.keys()))
ing = 0
end = 50
already = []
continue
else:
break
添加提示功能以及继续玩 奖金就莫得了 |