它应该计算行的数量和行中字符的数量。你知道吗
我不能再向我的显示函数中添加变量了,正如教授所说的使用2。你知道吗
如果我改变zXX=zXX+1,就可以正确地计算行中的字符 至zXX=w 但如果我这样做,它不会计算的行数,如果有人能帮助我将不胜感激。你知道吗
目前我有:
def display(x, y): y = str(y) varx = str(len(y)) vary = y + "#" + x + "#" + varx return vary.rjust(3) def main(): script = '''Grandson|Cough, cough, cough. Cough, cough, cough. {Grandson is on the bed, playing video game.} Mother|{Enters.} Hi, honey. Grandson|Hi, Mom. Mother|{Kisses son and feels his forehead.} You feeling any better? Grandson|A little bit. Mother|Guess what? Grandson|What? Mother|Your Grandfather's here. {Opens curtains.} Grandson|Mom, can't you tell him I'm sick? Mother|You're sick? That's why he's here. Grandson|He'll pinch my cheek. I hate that. Mother|Maybe he won't. Grandfather|{Entering with a flourish.} Heyyyy!! How's the sickie? Heh? {Pinches boy's cheek. Boy looks at mother accusingly.} Mother|I think I'll leave you two pals alone. {Exits.} Grandfather|I brought you a special present. Grandson|What is it? Grandfather|Open it up. Grandson|{Opens the package. Disappointed.} A book? Grandfather|That's right. When I was your age, television was called books. And this is a special book. It was the book my father used to read to me when I was sick, {takes book} and I used to read it to your father. And today I'm gonna read it to you. Grandson|Has it got any sports in it? Grandfather|Are you kidding? Fencing, fighting, torture, revenge, giants, monsters, chases, escapes, true love, miracles... Grandson|Doesn't sound too bad. I'll try to stay awake. {Turns off TV.} Grandfather|Oh, well, thank you very much, very nice of you. Your vote of confidence is overwhelming. All right. {Puts glasses on.} The Princess Bride, by S. Morgenstern. Chapter One. Buttercup was raised on a small farm in the country of Florin.''' zX = script.split('\n') #print(zX) zXX = 0 for w in zX: #print(zX[zXX:(zXX + 1)]) zXXXX = w.split('|') #print(zXXXX) zXXX = zXXXX[0].upper() + " " + zXXXX[1] #print(zXXX) zXX = zXX + 1 print(display(zXXX, zXX)) main()
输出为:
孙子咳嗽,咳嗽,咳嗽。咳嗽,咳嗽,咳嗽。{孙子在床上玩电子游戏。}1
2#妈妈{进来了。}嗨,亲爱的。#1
孙子嗨,妈妈
4#母亲{亲吻儿子,摸摸他的额头。}你感觉好些了吗?#1个
5#孙子一点点。#1
妈妈猜怎么着?#1个
孙子什么?#1个
妈妈你爷爷来了。{拉开窗帘。}1
孙子妈妈,你不能告诉他我病了吗?#1个
妈妈你病了?这就是他来这里的原因
孙子,他会捏我的脸颊。我讨厌那样
母亲也许他不会
13#爷爷{兴高采烈地走进来。}嘿!!病人怎么样了?嘿? {捏男孩的脸颊。男孩责备地看着母亲
14#妈妈,我想我会让你们两个朋友单独待着。{出口}#2
15#爷爷我给你带来了一份特别的礼物。#2
孙子这是什么?#二
17#爷爷打开它。#2
18#孙子{打开包裹。失望。}一本书?#二
爷爷,没错。我像你这么大的时候,电视叫书。这是一本特别的书。这是我生病时父亲常给我读的书,我也常给你父亲读。今天我要读给你听
孙子,里面有什么运动吗?#二
爷爷你在开玩笑吗?击剑,战斗,折磨,复仇,巨人,怪物,追逐,逃跑,真爱,奇迹…#2
孙子听起来并不坏。我尽量保持清醒。{关掉电视。}#2
23#爷爷哦,好吧,非常感谢你,非常感谢你。你的信任票是压倒性的。好吧。{戴上眼镜。}《公主新娘》,作者:S.摩根斯坦。第一章。毛茛是在弗罗林的一个小农场里长大的
一旦我通过了格式化和变量名,并且您没有在“script”中包含换行符,我很确定问题是您有:
而不是:
虽然这是基于我对你提供的解释
相关问题 更多 >
编程相关推荐