Skip to main content
 首页 » 编程设计

Python如何输入4个单词的列表和 "fill in the blanks"造句

2025年05月04日15lautakyan007

到目前为止我有

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])    

所以这句话应该是:用你 Shiny 的扫帚,向天空跳吧!

但它正在打印:用你的形容词名词和动词指向这个地方!

有什么想法我错过了什么吗?

请您参考如下方法:

也许是这样的,您可以根据需要的单词类型对输入列表进行索引?

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]+'!')