#!/usr/bin/python
# -*- coding: utf-8 -*-
Import random
from urllib import urlopen
Import sys
for word in urlopen(WORLD_URL).readlines( ):
WORDS.append( word.strip( ) )
WORD_URL = 'http://learncodethehardway.org/words.txt'
WORDS = []
#do they want to drill phrases first
PHRASE_FIRST = False
if len(sys.argv) == 2 and sys.argv[1] == 'english':
PHRASE_FIRST = True
# load up the words from the website
for word in urlopen(WORD_URL).readlines():
WORD.append(word.strip())
def convert(snippet,phrase):
class_names = [w.capitalize() for w in random.sample(WORDS,snippet.count('%%%'))]
other_names = random.sample(WORDS,snippet.count('***'))
results = []
param_names = []
for i in range(0,snippet.count('@@@')):
param_count = random.randint(1,3)
param_names.append(', '.join(random.sample(WORDS,param_count)))
for sentence in snippet,phrase:
result = sentence[:]
#fake class param_names
for word in class_names:
result = result.replace('%%%',word,1)
# fake other class_names
for word in other_names:
result = result.replace('***',word,1)
# fake parameter lists
for word in param_names:
result = result.replace('@@@',word,1)
results.append(result)
return results
# keep going until they hit CTRL-D
try:
while True:
snippets = PHRASES.keys()
random.shuffle(snippets)
for snippet in snippets:
phrase = PHRASES[snippet]
question,answer = convert(snippet,phrase)
if PHRASES_FIRST:
question,answer = answer,question
print(question)
input('>')
print('answer: %s\n\n'%answer)
except EOFError:
print('\nBye')
习题41
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 下面是培臻教育小编为大家整理的一篇关于LSAT考试逻辑推理练习题(41)的文章,供大家参考,下面是详细内容。 83...
- ①from sys import exit 从sys模组中引入exit即退出功能 退出程序的方式有两种:os._e...