import sys
import requests
from bs4 import BeautifulSoup
from lxml import etree
import random
print('\033[33m')
print('欢迎来到单词的世界!')
print('在这里,你将用给定的字母拼出单词,单词越长,得分越高')
print('现在好好享受单词的魅力吧')
print('\033[0m')
input('输入go开始游戏')
# 游戏模块
level = int(input('请选择难度(1~10):'))
# 初始字母数
start_num = int(26/level)
# 当前可用字母存放的地方
letter = []
# 已经拼写出来的单词存放的地方
words = []
# 26个字母列表
letter_list = []
# 元音字母列表
yuan_yin = ['a', 'o', 'i', 'e', 'u']
# 分数
score = 0
# 游戏是否继续
game = True
# 检查次数
check_no = 1
# 程序暂停
game_exit = 1
# 当前翻译
one = set()
# 字母修改次数
re_num = 11 - level
for i in range(97, 123): # 生成含有26个英文字母的列表
letter_list.append(chr(i))
# 随机放入start_num个字母
for i in range(1, start_num):
x = random.randrange(97, 123)
letter.append(chr(x))
x = random.randrange(97, 123)
letter.append(chr(x))
x = random.randrange(97, 123)
letter.append(chr(x))
x = random.randrange(97, 123)
letter.append(chr(x))
for n in range(1, start_num):
y = random.randrange(1, len(yuan_yin))
letter.append(yuan_yin[y-1])
# 辅音字母列表
fu_yin = letter_list
for an in yuan_yin:
if an in fu_yin:
fu_yin.remove(str(an))
def find_word(word): # 定义查找单词函数
url = 'http://dict.youdao.com/w/eng/{}/#keyfrom=dict2.index'.format(word)
website = requests.get(url).text
global one
global transform
html = BeautifulSoup(website, 'lxml')
trans = html.find(class_='trans-container')
if str(type(trans)) == 'NoneType':
exit(0)
else:
transform = trans.find_all('li')
if str(type(transform)) == 'NoneType':
exit(0)
for sa in transform:
if type != 'NoneType':
print('\033[36m' + sa.string + '\033[0m')
else:
return 0
if len(transform) > 0:
return word
else:
return 0
def write(): # 输入单词并检查函数
global game_exit
new_letter = letter
fre = []
# 检查是否在给出的字母表里
for zi_mu in dan_ci:
if zi_mu not in new_letter:
04-08
1183
