python3 RNG变量

时间:2018-06-20 03:37:43

标签: python-3.x

进行了2天的编码,遇到了障碍。

我想做些有趣的小练习,以帮助一些人练习英语。

基本上,他们输入想要练习的单词,然后随机生成器抛出句子供他们阅读。

问题是我想纠正语法错误,我做了两种不同的“代词”类别和2种不同的“动词”类别。

我如何将它们链接在一起,但仍然保留了一个随机元素,即永远不知道会得到什么组合,但仍然使其遵循语法规则。

下面的代码,任何帮助都将很棒= D

# coding: utf-8

# In[73]:

noun1 = ("apple", "peach", "plum", "cat", "dog", "mouse")
verb1 = ("drink", "eat", "swim", "kill", "kick", "hit", "die")
# verb + S 
verbS = ("drinks", "eats", "swims", "kills", "kicks", "hits", "dies")
adj1 = ("blue", "black", "red","big", "small", "tall", "short")
direction1 = ("up", "in", "out", "behind", "infront of", "over")
#pronouns Capital
Pronoun1 = ("I", "You", "They", "We")
PronounS = ("He", "She","Tt")
#pronouns non Capital
pronoun1 = ("I", "you", "they", "we")
pronounS = ("he", "she","it")

# In[74]:

import random

# In[75]:

def sentence1():
    print(random.choice(Pronoun1),end=" ")
    print(random.choice(verb1),end=" ")
    print("the",end=" ")
    print(random.choice(adj1),end=" ")
    print(random.choice(noun1),end=" ")
    return"."

# In[82]:

print(sentence1())

0 个答案:

没有答案