poem quiz古诗词填空出题器

这天下午,在当小学老师的闺蜜在判学生默写的古诗判烦了的时候突然想到,要是诗词填空就好了就不用判整首诗了,于是她找上了我,问我能不能做个出诗词填空的程序。于是就写了这个小玩意,大致思路很简单,random一个数,然后把这句话替换掉。

(github链接)

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
import numpy as np
import string
import sys
def save_to_file(file_name, contents):
filename = sys.argv[0] + '/'+ file_name
fh = open(file_name, 'a')
fh.write(contents)
fh.close()
def quiz1poem():
row_poem = input("请输入古诗词:")
punc = string.punctuation
if row_poem[len(row_poem)-1] in punc:
row_poem = row_poem[:-1]
sentences0 = row_poem.split()
sentences1 = []
sentences = []
for sentence in sentences0:
sentence = sentence.split(',')
sentences1 = sentence + sentences1
for sentence in sentences1:
sentence = sentence.split('。')
sentences = sentence + sentences
# print(sentences)
re_index = np.random.randint(0,len(sentences)-1)
sentences[re_index] = '_____________'
output = ""
for sentence in sentences:
output = output + "\n" + sentence
print(output)
return output

if __name__ == "__main__":
quitORconti = '0'
while quitORconti.lower() != 'q':
output = quiz1poem()
save_to_file("poem_quiz.txt", output)
quitORconti = input("Enter q to quit the pro! Press any key to continue!")

测试结果如下:

最后我们暗戳戳的想干脆出几套唐诗三百首随机填空的题考试吧【会被学生打死

Share