Python 类型错误:';非类型';

Python 类型错误:';非类型';,python,python-3.x,Python,Python 3.x,好吧,我在代码中遇到了这个荒谬的错误,而其他stackoverflow错误似乎都没有帮助。我需要帮助找出这段代码的错误,特别是在defmakepooth()部分 import random noun = ["fossil" , "horse" , "aardvark" , "chef" , "judge"] verb= [ "kicks", "jingles", "bounces", "slurps", "meows"] adjs= ["fury" , "balding" , "incredu

好吧,我在代码中遇到了这个荒谬的错误,而其他stackoverflow错误似乎都没有帮助。我需要帮助找出这段代码的错误,特别是在
defmakepooth()
部分

import random

noun = ["fossil" , "horse" , "aardvark" , "chef" , "judge"]
verb= [ "kicks", "jingles", "bounces", "slurps", "meows"]
adjs= ["fury" , "balding" , "incredulous" , "fragant"]
prep= ["against" , "after" , "into" , "beneath" , "for", "in"]
ads= ["curiously" , "extravagantly" , "furiously" , "sensuously"]

def selectn(list, n) :
selection = []
while (len(selection) != n) : 
    w = random.choice(list)
    if w not in selection :
        selection.append(w)
print(selection)
# For some reason I'm getting TypeError: 'NoneType' object is not subscriptable for "makePoem()" 
def makePoem() :
    my_nouns = selectn(noun,3)
    my_verbs = selectn(verb,3)
    my_adj = selectn(adjs,3)
    my_adverb = selectn(ads,1)
    my_prepo = selectn(prep,2)

print ("A {} {}".format(my_adj[0], my_nouns[0]))
print("")
print("A {} {} {} {} the {} {}".format(my_adj[0], my_nouns[0], my_verbs[0], my_prepo[0], my_adj[1], my_nouns[1]))
print("{}, the {} {}".format(my_adverb[0], my_nouns[0], my_verbs[1]))
print("the {} {} {} a {} {}".format(my_nouns[1], my_verbs[2], my_prepo[1], my_adj[2], my_nouns[2]))
makePoem()    

`

您没有返回
选择,而是打印它。将
print(selection)
替换为
return selection

是否
selectn()
应该返回一些东西?
selectn()
返回字符串
selection
。当你发布“为什么我的代码不起作用”问题时,你应该:1)告诉你得到了什么行为以及你期望得到什么行为,2)确保您的示例具有您声称的行为。发布的代码格式不正确,因此不会有您声称的行为。此外,准确的错误消息通常很有帮助,因为在python中,它通常会告诉错误在哪里。感谢@skyking I will do的评论@如果它解决了你的问题,就用CatGod6标记作为答案。8分钟后我再标记,但我会做的!