如何解决Mad Lib 生成器,字符串对齐
嗨,我正在尝试创建 Mad lib 生成器,但输出未正确对齐。任何人请帮助我。 我的代码是
GirlsName=input("A girl's name :")
Number=input("A number :")
Emotion=input("An emotion :")
Place=input("A place :")
BoysName=input("A boy's Name :")
AnotherNumber=input("Another Number :")
NumLessFifty=input("A Number Less than 50 :")
MoreNumber=input("One more number :")
ReindeerName=input("A Reindeer's Name :")
AnotherEmotion=input("Another Emotion :")
Action=input("What you want to do build story or start over:")
if(Action=="build"):
###Mad Lib: The Christmas Surprise###
print("STORY THE CHRISTMAS SURPRISE")
Story="""{0}woke up one Christmas Day to find that she had no presents!
On the end of her bed she found a letter from {1} of Santa's eleves.
It said that Santa was very {2}.
After she had read the letter,She found herself being whisked off to the {3}.
There she met an elf whose name was {4}. He said that he was Santa's helper.
Because Santa was happy,{0} had to deliver all {5} presents to everyone around the world before they woke up.
{8} was in front and off they went.
It was a hard job but in the end they did it in {6} minutes.
When she arrived back home,she found {7} on her bed. She was so {9}."""
newstring=Story.format(GirlsName,Number,Emotion,Place,BoysName,AnotherNumber,NumLessFifty,MoreNumber,ReindeerName,AnotherEmotion)
print(newstring.rjust(10))
我得到的输出是
圣诞惊喜的故事 莉莉在圣诞节那天醒来,发现她没有礼物! 在她的床尾,她发现了一封来自圣诞老人的两个小精灵的信。 它说圣诞老人很高兴。 看完信后,她发现自己被带到了公园。 在那里,她遇到了一个名叫约翰的精灵。他说他是圣诞老人的帮手。 因为圣诞老人很高兴,莉莉不得不在他们醒来之前将所有 37 份礼物分发给世界各地的每个人。 基拉在前面,他们走了。 这是一项艰苦的工作,但最终他们在 20 分钟内完成了。 当她回到家时,她在床上发现了 3 个。她好伤心。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。