python输出一首诗_Python:如何打印我的简单诗

像往常一样(对我来说),可能还有一种更像Python的方法,但为了让你的工作发挥作用,我做了三件事:将对nomens()函数的调用分配给“choosed\u list”变量。这样就可以使用返回的“randomPick”。

内置一个选择步骤,从“choosed”列表和动词列表中获取单个单词

添加了带格式的final print语句以将单词组合成一个句子

代码:import random

def nouns():

nounPersons = ["cow","crowd","hound","clown"];

nounPlace = ["town","pound","battleground","playground"];

rhymes = ["crowned","round","gowned","found","drowned"];

nounPersons2 = ["dog","frog","hog"];

nounPlace2 = ["fog","Prague","smog"];

rhymes2 = ["log","eggnog","hotdog"];

nounList1 = [nounPersons,nounPlace,rhymes]

nounList2 = [nounPersons2,nounPlace2,rhymes2]

nounsList = [nounList1, nounList2]

randomPick = random.choice(nounsList)

return randomPick

verbs = ["walked","ran","rolled","biked","crawled"]

# this is change 1.

chosen_list = nouns()

# select single words from lists - this is change 2.

noun_subj = random.choice(chosen_list[0])

noun_obj = random.choice(chosen_list[1])

rhyme_word = random.choice(chosen_list[2])

verb_word = random.choice(verbs)

# insert words in to text line - this is change 3.

print ("The {} {} to the {}. But then it was {}.".format(noun_subj, verb_word, noun_obj, rhyme_word))

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值