我需要写一个脚本,当琼睡觉,琼的妈妈睡觉,琼的妈妈的表妹睡觉时,生成不同的句子。琼的姐姐的丈夫的哥哥睡觉等等。为此,我编写了一个包含8个函数的代码,如下所示。现在我想写第二步,它将要求输入一个句子使用家庭成员,如“我表弟的母亲睡觉”,并显示采取了哪些步骤来生成这个句子。到目前为止,我掌握的情况如下:
# _*_ coding: utf-8 _*_
import random
def etat7(chaine):
return chaine+"dort."
def etat6(chaine):
choix=random.choice(range(0,3))
if choix==0:
mot="Jean "
return etat7(chaine+mot)
elif choix==1:
mot="la "
return etat3(chaine+mot)
elif choix==2:
mot="l' "
return etat4(chaine+mot)
def etat5(chaine):
choix=random.choice(range(0,2))
if choix==0:
mot="de "
return etat6(chaine+mot)
if choix==1:
mot="du "
return etat2(chaine+mot)
def etat4(chaine):
choix=random.choice(range(0,2))
if choix==0:
mot="ancêtre "
return etat5(chaine+mot)
elif choix==1:
mot="oncle "
return etat5(chaine+mot)
def etat3(chaine):
choix=random.choice(range(0,3))
if choix==0:
mot="mère "
return etat5(chaine+mot)
elif choix==1:
mot="soeur "
return etat5(chaine+mot)
elif choix==2:
mot="nièce "
return etat5(chaine+mot)
def etat2(chaine):
choix=random.choice(range(0,3))
if choix==0:
mot="père "
return etat5(chaine+mot)
elif choix==1:
mot="frère "
return etat5(chaine+mot)
elif choix==2:
mot="neveu "
return etat5(chaine+mot)
def etat1(chaine):
choix=random.choice(range(0,3))
if choix==0:
mot="le "
return etat2(chaine+mot)
elif choix==1:
mot="la "
return etat3(chaine+mot)
elif choix==2:
mot="l' "
return etat4(chaine+mot)
print etat1("")
在这一步,我有一个程序,生成不同的句子,但我不明白如何进行。你知道吗
谢谢
获取输出并向后分析
相关问题 更多 >
编程相关推荐