-3

所以,我需要用函数来写这首儿歌,而不仅仅是每行重复的打印代码。歌词在下面,我也包括了我到目前为止所拥有的。接下来我该怎么做?

有一位老太太吞下了一只苍蝇。
我不知道她为什么吞下苍蝇。
也许她会死。

有一位老妇人吞下了一只蜘蛛,
它在她体内蠕动、摇晃和挠痒痒。
她吞下蜘蛛来捉苍蝇。
我不知道她为什么吞下苍蝇。
也许她会死。

有一位老太太吞下了一只鸟。
吞下一只鸟是多么荒谬。
她吞下鸟去抓蜘蛛,
它在她体内蠕动、摇晃和挠痒痒。
她吞下蜘蛛来捉苍蝇。
我不知道她为什么吞下苍蝇。
也许她会死。

有一位老太太吞下了一只猫。
想象一下吞下一只猫。
她吞下猫来抓鸟。
她吞下鸟去抓蜘蛛,
它在她体内蠕动、摇晃和挠痒痒。
她吞下蜘蛛来捉苍蝇。
我不知道她为什么吞下苍蝇。
也许她会死。

有一位老太太吞下了一条狗。
我的,真是一头猪,吞下一条狗。
她吞下狗来抓猫。
她吞下猫来抓鸟。
她吞下鸟去抓蜘蛛,
它在她体内蠕动、摇晃和挠痒痒。
她吞下蜘蛛来捉苍蝇。
我不知道她为什么吞下苍蝇。
也许她会死。

有一位老太太吞了一匹马。
她当然死了。

到目前为止,我有:

def main():
     title()  # print the title
     verse1() # fly verse
     verse2() # spider verse
     verse3() # bird verse      
     verse4() # cat verse      
     verse5() # dog verse
     lastverse() # horse verse

there was an old lady who swolled a %
# call main
main()
4

1 回答 1

1
def title():
    text = """
     A children song
    """
    print(text)

def verse1():
    text = """
    There was an old lady who swallowed a fly.
    I don't know why she swallowed the fly.
    Perhaps she'll die.
    """
    print(text)

def verse2():
    text = """
    There was an old lady who swallowed a spider,
    That wriggled and jiggled and tickled inside her.
    She swallowed the spider to catch the fly.
    I don't know why she swallowed the fly.
    Perhaps she'll die.
    """
    print(text)
def verse3():
    text = """
    There was an old lady who swallowed a bird.
    How absurd to swallow a bird.
    She swallowed the bird to catch the spider,
    That wriggled and jiggled and tickled inside her.
    She swallowed the spider to catch the fly.
    I don't know why she swallowed the fly.
    Perhaps she'll die.
    """
    print(text)

def verse4():
    text = """
    There was an old lady who swallowed a cat.
    Imagine that to swallow a cat.
    She swallowed the cat to catch the bird.
    She swallowed the bird to catch the spider,
    That wriggled and jiggled and tickled inside her.
    She swallowed the spider to catch the fly.
    I don't know why she swallowed the fly.
    Perhaps she'll die.
    """
    print(text)
def verse5():
    text = """
    There was an old lady who swallowed a dog.
    My, what a hog, to swallow a dog.
    She swallowed the dog to catch the cat.
    She swallowed the cat to catch the bird.
    She swallowed the bird to catch the spider,
    That wriggled and jiggled and tickled inside her.
    She swallowed the spider to catch the fly.
    I don't know why she swallowed the fly.
    Perhaps she'll die.
    """
    print(text)

def lastverse():
    text = """
    There was an old lady who swallowed a horse.
    She's dead, of course.
    """
    print(text)

def main():
    title()  # print the title
    verse1()  # fly verse
    verse2()  # spider verse
    verse3()  # bird verse
    verse4()  # cat verse
    verse5()  # dog verse
    lastverse()  # horse verse

main()
于 2013-07-19T05:26:46.060 回答