为Python 3编写脚本:儿歌

时间:2013-07-19 05:01:10

标签: python

所以,我需要用功能编写这首儿歌,而不仅仅是为每一行重复打印代码。歌词在下面,我也包括了我到目前为止的内容。我接下来该怎么办?

  

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

     

有一位老太太吞下一只蜘蛛,
  那里面扭动着,扭动着,发痒   她吞下蜘蛛抓住苍蝇   我不知道为什么她吞下苍蝇   也许她会死的。

     

有一位老太太吞下了一只鸟   吞下一只鸟是多么荒谬   她吞下那只鸟抓住蜘蛛,
  那里面扭动着,扭动着,发痒   她吞下蜘蛛抓住苍蝇   我不知道为什么她吞下苍蝇   也许她会死的。

     

有一位老太太吞下了一只猫   想象一下吞下一只猫   她吞下了猫抓住这只鸟   她吞下那只鸟抓住蜘蛛,
  那里面扭动着,扭动着,发痒   她吞下蜘蛛抓住苍蝇   我不知道为什么她吞下苍蝇   也许她会死的。

     

有一位老太太吞下了一只狗   吞下一只狗,我的生猪是什么   她吞下了狗抓住猫   她吞下了猫抓住这只鸟   她吞下那只鸟抓住蜘蛛,
  那里面扭动着,扭动着,发痒   她吞下蜘蛛抓住苍蝇   我不知道为什么她吞下苍蝇   也许她会死的。

     

有一位老太太吞下了一匹马   当然,她已经死了。

到目前为止,我有:

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

1 个答案:

答案 0 :(得分: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()