- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如果这个问题已在其他地方得到回答,我很抱歉。我是一个100%的初学者。我正在 codeacademy 工作,其中一个项目是 Madlib。我已经将它转移到 Visual Studio 并从头开始自己做了一些。我的想法是创建一个庞大的基线 MadLib,这样我所要做的就是用适当的必要变量写出故事。当我运行这个程序时,它可以工作,但它要求每一个输入。如何让程序只询问故事所需的特定变量?提前致谢,这是代码。
""" Newscast MadLib by Salem
"""
print ("Here comes a MadLib yall!!!")
noun1 = input("Enter a Noun: " )
noun2 = input("Enter a Noun: " )
noun3 = input("Enter a Noun: " )
noun4 = input("Enter a Noun: " )
noun5 = input("Enter a Noun: " )
adj1 = input("Enter an Adjective: ")
adj2 = input("Enter an Adjective: ")
adj3 = input("Enter an Adjective: ")
adj4 = input("Enter an Adjective: ")
adj5 = input("Enter an Adjective: ")
verb1 = input("Enter a Verb: ")
verb2 = input("Enter a Verb: ")
verb3 = input("Enter a Verb: ")
verb4 = input("Enter a Verb: ")
verb5 = input("Enter a Verb: ")
adv1 = input("Enter a Adverb: ")
adv2 = input("Enter a Adverb: ")
adv3 = input("Enter a Adverb: ")
adv4 = input("Enter a Adverb: ")
adv5 = input("Enter a Adverb: ")
verbing1 = input("Enter a Verb ending in ing: ")
verbing2 = input("Enter a verb ending in ing: ")
verbing3 = input("Enter a verb ending in ing: ")
verbs1 = input("Enter a verb ending in S: ")
verbs2 = input("Enter a verb ending in S: ")
verbs3 = input("Enter a verb ending in S: ")
pnoun1 = input("Enter a Proper Noun: ")
pnoun2 = input("Enter a Proper Noun: ")
pnoun3 = input("Enter a Proper Noun: ")
pnoun4 = input("Enter a Proper Noun: ")
pnoun5 = input("Enter a Proper Noun: ")
plnoun1 = input("Enter a Plural Noun: ")
plnoun2 = input("Enter a Plural Noun: ")
plnoun3 = input("Enter a Plural Noun: ")
plnoun4 = input("Enter a Plural Noun: ")
plnoun5 = input("Enter a Plural Noun: ")
body1 = input("Enter a Body Part: ")
body2 = input("Enter a Body Part: ")
body3 = input("Enter a Body Part: ")
body4 = input("Enter a Body Part: ")
body5 = input("Enter a Body Part: ")
bodypl1 = input("Enter a part of the body Plural: ")
bodypl2 = input("Enter a part of the body Plural: ")
bodypl3 = input("Enter a part of the body Plural: ")
emotion1 = input("Enter an Emotion: ")
emotion2 = input("Enter an Emotion: ")
emotion3 = input("Enter an Emotion: ")
historicm1 = input("Enter a Historic Monument: ")
historicm2 = input("Enter a Historic Monument: ")
mansname1 = input("Enter a Mans Name: ")
mansname2 = input("Enter a Mans Name: ")
womname1 = input("Enter a Womans Name: ")
womname2 = input("Enter a Womans Name: ")
occup1 = input("Enter an Occupation: ")
occup2 = input("Enter an Occupation: ")
occup3 = input("Enter an Occupation: ")
shape1 = input("Enter a Shape: ")
shape2 = input("Enter a Shape: ")
shape3 = input("Enter a Shape: ")
rest1 = input("Enter a Restaurant Name: ")
rest2 = input("Enter a Restaurant Name: ")
rest4 = input("Enter a Restaurant Name: ")
liquid1 = input("Enter a type of Liquid: ")
liquid2 = input("Enter a type of Liquid: ")
personir1 = input("Enter the name of someone in the room: ")
personir2 = input("Enter the name of someone in the room: ")
personir4 = input("Enter the name of someone in the room: ")
food1 = input("Enter a type of Food: ")
food2 = input("Enter a type of Food: ")
food3 = input("Enter a type of Food: ")
fperson1 = input("Enter the name of a famous person: ")
fperson2 = input("Enter the name of a famous person: ")
fperson3 = input("Enter the name of a famous person: ")
sword1 = input("Enter a Silly Word: ")
sword2 = input("Enter a Silly Word: ")
sword3 = input("Enter a Silly Word: ")
num1 = input("Enter a Number: ")
num2 = input("Enter a Number: ")
num3 = input("Enter a Number: ")
num4 = input("Enter a Number: ")
num5 = input("Enter a Number: ")
place1 = input("Enter a Place: ")
place2 = input("Enter a Place: ")
place3 = input("Enter a Place: ")
place4 = input("Enter a Place: ")
place5 = input("Enter a Place: ")
story = ("Putting on a newscast might look easy, but it takes a lot of %s work. Go behind the scenes, and you will see dozens of %s workers %s in every direction! Reporters run back and forth between the studio and locations all around %s to cover %s stories and interview %s . They are joined by videographers who operate handheld %s to capture all the action. The anchors are the people who %s behind the news desk and read the stories during the newsccast. They have to look %s on air, so they can often be found getting makeup applied to their %s . The director tells everyone where and when to %s . Its easy to spot a director because he wears a headset on his %s and yells things like CAMERA TWO and %s ! A newscast is live television so if you make aor an %s mistake, everyone watching at home on their %s will know!")
story = story % (adj1, adj2, verbing1, place1, adj3, plnoun1, plnoun2, verb1, adj4, bodypl1, verb2,
body1, sword1, adj5, plnoun3)
print (story)
我正在为此苦苦挣扎,哈哈,我感谢所有的帮助。这是修订版
""" Newscast MadLib by Salem
"""
print ("Here comes a MadLib yall!!!")
noun1 = input("Enter a Noun: " )
noun2 = input("Enter a Noun: " )
noun3 = input("Enter a Noun: " )
noun4 = input("Enter a Noun: " )
noun5 = input("Enter a Noun: " )
adj1 = input("Enter an Adjective: ")
adj2 = input("Enter an Adjective: ")
adj3 = input("Enter an Adjective: ")
adj4 = input("Enter an Adjective: ")
adj5 = input("Enter an Adjective: ")
verb1 = input("Enter a Verb: ")
verb2 = input("Enter a Verb: ")
verb3 = input("Enter a Verb: ")
verb4 = input("Enter a Verb: ")
verb5 = input("Enter a Verb: ")
adv1 = input("Enter a Adverb: ")
adv2 = input("Enter a Adverb: ")
adv3 = input("Enter a Adverb: ")
adv4 = input("Enter a Adverb: ")
adv5 = input("Enter a Adverb: ")
verbing1 = input("Enter a Verb ending in ing: ")
verbing2 = input("Enter a verb ending in ing: ")
verbing3 = input("Enter a verb ending in ing: ")
verbs1 = input("Enter a verb ending in S: ")
verbs2 = input("Enter a verb ending in S: ")
verbs3 = input("Enter a verb ending in S: ")
pnoun1 = input("Enter a Proper Noun: ")
pnoun2 = input("Enter a Proper Noun: ")
pnoun3 = input("Enter a Proper Noun: ")
pnoun4 = input("Enter a Proper Noun: ")
pnoun5 = input("Enter a Proper Noun: ")
plnoun1 = input("Enter a Plural Noun: ")
plnoun2 = input("Enter a Plural Noun: ")
plnoun3 = input("Enter a Plural Noun: ")
plnoun4 = input("Enter a Plural Noun: ")
plnoun5 = input("Enter a Plural Noun: ")
body1 = input("Enter a Body Part: ")
body2 = input("Enter a Body Part: ")
body3 = input("Enter a Body Part: ")
body4 = input("Enter a Body Part: ")
body5 = input("Enter a Body Part: ")
bodypl1 = input("Enter a part of the body Plural: ")
bodypl2 = input("Enter a part of the body Plural: ")
bodypl3 = input("Enter a part of the body Plural: ")
emotion1 = input("Enter an Emotion: ")
emotion2 = input("Enter an Emotion: ")
emotion3 = input("Enter an Emotion: ")
historicm1 = input("Enter a Historic Monument: ")
historicm2 = input("Enter a Historic Monument: ")
mansname1 = input("Enter a Mans Name: ")
mansname2 = input("Enter a Mans Name: ")
womname1 = input("Enter a Womans Name: ")
womname2 = input("Enter a Womans Name: ")
occup1 = input("Enter an Occupation: ")
occup2 = input("Enter an Occupation: ")
occup3 = input("Enter an Occupation: ")
shape1 = input("Enter a Shape: ")
shape2 = input("Enter a Shape: ")
shape3 = input("Enter a Shape: ")
rest1 = input("Enter a Restaurant Name: ")
rest2 = input("Enter a Restaurant Name: ")
rest4 = input("Enter a Restaurant Name: ")
liquid1 = input("Enter a type of Liquid: ")
liquid2 = input("Enter a type of Liquid: ")
personir1 = input("Enter the name of someone in the room: ")
personir2 = input("Enter the name of someone in the room: ")
personir4 = input("Enter the name of someone in the room: ")
food1 = input("Enter a type of Food: ")
food2 = input("Enter a type of Food: ")
food3 = input("Enter a type of Food: ")
fperson1 = input("Enter the name of a famous person: ")
fperson2 = input("Enter the name of a famous person: ")
fperson3 = input("Enter the name of a famous person: ")
sword1 = input("Enter a Silly Word: ")
sword2 = input("Enter a Silly Word: ")
sword3 = input("Enter a Silly Word: ")
num1 = input("Enter a Number: ")
num2 = input("Enter a Number: ")
num3 = input("Enter a Number: ")
num4 = input("Enter a Number: ")
num5 = input("Enter a Number: ")
place1 = input("Enter a Place: ")
place2 = input("Enter a Place: ")
place3 = input("Enter a Place: ")
place4 = input("Enter a Place: ")
place5 = input("Enter a Place: ")
def entera(adj1, adj2, verbing1, place1, adj3, plnoun1, plnoun2, verb1, adj4, bodypl1, verb2, body1, sword1, adj5, plnoun3):
input("Enter a {}: ".format(adj1))
input("Enter a {}: ".format(adj2))
input("Enter a {}: ".format(verbing1))
input("Enter a {}: ".format(place1))
input("Enter a {}: ".format(adj3))
input("Enter a {}: ".format(plnoun1))
input("Enter a {}: ".format(plnoun2))
input("Enter a {}: ".format(verb1))
input("Enter a {}: ".format(adj4))
input("Enter a {}: ".format(bodypl1))
input("Enter a {}: ".format(verb2))
input("Enter a {}: ".format(body1))
input("Enter a {}: ".format(sword1))
input("Enter a {}: ".format(adj5))
input("Enter a {}: ".format(plnoun3))
return (adj1, adj2, verbing1, place1, adj3, plnoun1, plnoun2, verb1, adj4, bodypl1, verb2, body1, sword1, adj5, plnoun3)
story = ("Putting on a newscast might look easy, but it takes a lot of {} work. Go behind the scenes, and you will see dozens of {} workers {} in every direction! Reporters run back and forth between the studio and locations all around {} to cover {} stories and interview {} . They are joined by videographers who operate handheld {} to capture all the action. The anchors are the people who {} behind the news desk and read the stories during the newsccast. They have to look {} on air, so they can often be found getting makeup applied to their {} . The director tells everyone where and when to {} . Its easy to spot a director because he wears a headset on his {} and yells things like CAMERA TWO and {} ! A newscast is live television so if you make aor an {} mistake, everyone watching at home on their {} will know!")
story = story.format(entera("adj1", "adj2", "verbing1", "place1", "adj3", "plnoun1", "plnoun2", "verb1", "adj4", "bodypl1", "verb2", "body1", "sword1", "adj5", "plnoun3"))
print (story)
这是它抛出的错误
Exception has occurred: IndexError
Replacement index 1 out of range for positional args tuple
File "C:\Users\hgsal\Documents\python\ML Newscast", line 117, in <module>
story = story.format(entera("adj1", "adj2", "verbing1", "place1", "adj3", "plnoun1", "plnoun2", "verb1", "adj4", "bodypl1", "verb2", "body1", "sword1", "adj5", "plnoun3"))
最佳答案
您需要将输入推迟为字符串格式,而不是提前收集所有变量
def entera(desc):
return input("Enter a {}: ".format(desc))
story = "Putting on a newscast might look easy, but it takes a lot of {} work"
story = story.format(entera("Adjective"))
关于python - 如何在 Python 中仅请求 MadLib 中故事所需的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59347222/
我有一个依赖于包 B 的包 A。当包 A 中的代码运行并访问包 B 中的类时,包 B 的状态将被解析 (4),而不是 Activity (32) 和包 B 的激活器也没跑好。我认为 bundle B
这个问题在这里已经有了答案: How to remove the space between inline/inline-block elements? (41 个回答) 关闭 7 年前。
我正在尝试使用 Java OpenAL 库。我在导入名为 libsoft_oal.so 的 native 库时遇到问题。 Java OpenAL 依赖于 OpenAL 软实现。我尝试根据他们在 git
我正在尝试启动我的应用程序。是一个 unicorn +工头+sinatra的应用。 这是我的 config.ru 文件: require "rubygems" require "sinatra" Bu
我有一个下拉列表,其中包含一些从数据库表中检索的值,我想要的是当单击按钮时它应该只获得选项标签的中间值,但只有那些类名为“get_this”的选项标签并离开那些选项,如果他们没有这个类 预期输出:值
我有一个index.php文件,需要一个通用的head.php文件,head.php文件中有几个Javascript文件,当这样尝试时,代码在源代码中看起来很好,但文件却不是实际上对文档做任何事情。
有人能帮帮我吗? 我已经像这样运行了 imsmod: $ insmod /data/mm/mmdev.ko epoll_rate=100 但是我得到一个错误: insmod: init_module
是否有键盘快捷键或插件可以在 Notepad++ 中打开 PHP 所需或包含的文件?我知道,在 Dreamweaver 中,执行此操作的命令是 Ctrl+D,但我似乎无法在 Notepad++ 中找到
我已经用 js 设置了一个显示/隐藏 div,但我很难弄清楚如何一次显示一个 div。目前发生的情况是,除非我再次单击原始链接来关闭该 div,否则每个 div 都会显示。 http://www.li
当我尝试将未分配的辅助分片分配给节点时出现错误。 { "error": { "root_cause": [ { "type": "remote_transpor
我正在构建一个 C++ 应用程序,使用 Netbeans 6.9 作为我的 IDE。我有一个 C++ 库,它是一个纯 C 库的包装器。 我已将文件正确添加到项目中(使用添加库文件选项)。这是 g++
我是一名优秀的程序员,十分优秀!