In [8]:
import random
def get_str_table(line):
str_table=[]
for str_ in line:
if str_ not in str_table:
str_table.append(str_)
return str_table
def win():
print("你赢了!")
def lose():
print("你输了!")
def get_poem(line):
poems=[]
poems=line
return poems
def get_ch_table(line1,line2):
a=0
ch_table=[]
poem=[]
chtable=[]
poem=random.choice(line1)
ch_table.extend(poem)
for i in range(0,21):
ch_=random.choice(line2)
if ch_ not in chtable:
chtable.append(ch_)
for ch in chtable:
if ch not in ch_table:
ch_table.append(ch)
if len(ch_table)>=13:
return ch_table
break
else:
continue;
def get_mass(line):
random.shuffle(line)
return line
def check_poem(line1):
poems=[]
character=0
n=input("请输入正确的诗句:")
poems=list(n)
for poem in line1:
character=0
for ch in poem:
if ch in poems:
character=character+1
if character==7:
return win()
print(n)
return lose()
fh=open(r'd:\temp\poem.txt')
text=fh.read()
text=text.split()
text_=''.join(text)
fh.close()
line_=get_ch_table(text,text_)
print(get_mass(line_))
print(check_poem(text))