为python3编写脚本:一首儿童歌曲

2024-04-26 06:52:24 发布

您现在位置:Python中文网/ 问答频道 /正文

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

There was an old lady who swallowed a fly.
I don't know why she swallowed the fly.
Perhaps she'll die.

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.

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.

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.

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.

There was an old lady who swallowed a horse.
She's dead, of course.

到目前为止,我已经:

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

Tags: andthetoanoldspiderflywho
1条回答
网友
1楼 · 发布于 2024-04-26 06:52:24
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()

相关问题 更多 >