[英]Python how to input a list of 4 words and “fill in the blanks” to make a sentence
到目前为止,我有
def attack(words):
words = ['noun', 'verb', 'adjective', 'place']
print('Use your', words[2], words[0], 'and', words[1], 'towards the', words[3]+'!')
我要输入:
attack([shiny, broom, jump, sky])
因此该句子应为:用闪亮的扫帚跳向天空!
但它正在印刷:将您的形容词名词和动词用于该位置!
有什么想法我想念的吗?
也许是这样的事情,您根据需要的单词类型在输入列表中建立索引?
def attack(words):
noun, verb, adjective, place = 0, 1, 2, 3
print('Use your', words[adjective], words[noun], 'and', words[verb], 'towards the', words[place]+'!')
删除words = ["noun", "verb", "adjective", "place"]
。
您正在接受[shiny, broom, jump, sky]
作为attack()
函数的words
参数,并通过将["noun", "verb", "adjective", "place"]
分配给变量,立即覆盖该值同名。 此外,您的[shiny, broom, jump, sky]
列表中的元素缺少引号,除非这些引号是变量而不是字符串。
您的代码应为:
def attack(words):
print("Use your", words[2], words[0], "and", words[1], "towards the", words[3] + "!")
attack(["shiny", "broom", "jump", "sky"])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.