杰克的家【难度:2级】:

答案1:

VERSES = """\
This is the house that Jack built.This is the malt
that lay in the house that Jack built.This is the rat
that ate the malt
that lay in the house that Jack built.This is the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the farmer sowing his corn
that kept the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the horse and the hound and the horn
that belonged to the farmer sowing his corn
that kept the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.""".split("\n\n")def rhyme():return "\n\n".join(VERSES)def verse(n):return VERSES[n]​

答案2:

parts = [('lay in', 'the house that Jack built'),('ate', 'the malt'),('killed', 'the rat'),('worried', 'the cat'),('tossed', 'the dog'),('milked', 'the cow with the crumpled horn'),('kissed', 'the maiden all forlorn'),('married', 'the man all tattered and torn'),('woke', 'the priest all shaven and shorn'),('kept', 'the rooster that crowed in the morn'),('belonged to', 'the farmer sowing his corn'),('', 'the horse and the hound and the horn')]def verse(n):v = ['This is {}'.format(parts[n][1])]v.extend(['that {0} {1}'.format(parts[i][0], parts[i][1])for i in range(n - 1, -1, -1)])v[-1] += '.'return '\n'.join(v)def rhyme():return "\n\n".join(verse(n) for n in range(len(parts)))​

答案3:

def rhyme():return "\n\n".join(verses)verses = ["This is the house that Jack built.",
"This is the malt\nthat lay in the house that Jack built.",
"This is the rat\nthat ate the malt\nthat lay in the house that Jack built.",
"This is the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.",
"This is the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.",
"This is the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.",
"This is the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.",
"This is the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.",
"This is the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.",
"This is the rooster that crowed in the morn\nthat woke the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.",
"This is the farmer sowing his corn\nthat kept the rooster that crowed in the morn\nthat woke the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.",
"This is the horse and the hound and the horn\nthat belonged to the farmer sowing his corn\nthat kept the rooster that crowed in the morn\nthat woke the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built."]def verse(n):return verses[n]​

答案4:

def rhyme():return '\n\n'.join(verses)def verse(verse_no):return verses[verse_no] if verse_no<len(verses) else ''verses = 'This is the house that Jack built.\n\nThis is the malt\nthat lay in the house that Jack built.\n\nThis is the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the rooster that crowed in the morn\nthat woke the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the farmer sowing his corn\nthat kept the rooster that crowed in the morn\nthat woke the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the horse and the hound and the horn\nthat belonged to the farmer sowing his corn\nthat kept the rooster that crowed in the morn\nthat woke the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.'.split('\n\n')
​

答案5:

def rhyme():blocks = ['the house that Jack built.', 'the malt\nthat lay in', 'the rat\nthat ate','the cat\nthat killed', 'the dog\nthat worried', 'the cow with the crumpled horn\nthat tossed','the maiden all forlorn\nthat milked', 'the man all tattered and torn\nthat kissed','the priest all shaven and shorn\nthat married', 'the rooster that crowed in the morn\nthat woke','the farmer sowing his corn\nthat kept', 'the horse and the hound and the horn\nthat belonged to' ]res = []for i, string in enumerate(blocks): res.append('This is {}'.format(' '.join(reversed(blocks[:i + 1]))))return '\n\n'.join(res)def verse(verse_no):return rhyme().split('\n\n')[verse_no]​

答案6:

wall_of_text = ['''This is the house that Jack built.'''
,
'''This is the malt
that lay in the house that Jack built.'''
,
'''This is the rat
that ate the malt
that lay in the house that Jack built.'''
,
'''This is the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.'''
,
'''This is the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.'''
,
'''This is the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.'''
,
'''This is the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.'''
,
'''This is the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.'''
,
'''This is the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.'''
,
'''This is the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.'''
,
'''This is the farmer sowing his corn
that kept the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.'''
,
'''This is the horse and the hound and the horn
that belonged to the farmer sowing his corn
that kept the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.''']def rhyme():return '\n\n'.join(wall_of_text)def verse(verse_no):return wall_of_text[verse_no]
​

答案7:

song = [m.split('\n') for m in """This is the house that Jack built.This is the malt
that lay in the house that Jack built.This is the rat
that ate the malt
that lay in the house that Jack built.This is the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the farmer sowing his corn
that kept the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.This is the horse and the hound and the horn
that belonged to the farmer sowing his corn
that kept the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.""".split('\n\n')]def rhyme(): return "\n\n".join('\n'.join(r) for r in song)
def verse(verse_no): return '\n'.join(song[verse_no])​

答案8:

def rhyme():return '\n\n'.join(verse(i) for i in range(12))def verse(verse):nouns = ['house that Jack built', 'malt', 'rat', 'cat', 'dog', 'cow with the crumpled horn', 'maiden all forlorn', 'man all tattered and torn', 'priest all shaven and shorn', 'rooster that crowed in the morn', 'farmer sowing his corn', 'horse and the hound and the horn'][:verse+1]verbs = ['lay in', 'ate', 'killed', 'worried', 'tossed', 'milked', 'kissed', 'married', 'woke', 'kept' , 'belonged to'][:verse]s = ['This is the ' + nouns.pop()]while nouns:s.append('that '+ verbs.pop() + ' the ' + nouns.pop())return '\n'.join(s) + '.'​

答案9:

song = ['This is the horse and the hound and the horn', 'that belonged to the farmer sowing his corn', 'that kept the rooster that crowed in the morn', 'that woke the priest all shaven and shorn', 'that married the man all tattered and torn', 'that kissed the maiden all forlorn', 'that milked the cow with the crumpled horn', 'that tossed the dog', 'that worried the cat', 'that killed the rat', 'that ate the malt', 'that lay in the house that Jack built.']def rhyme():return 'This is the house that Jack built.\n\nThis is the malt\nthat lay in the house that Jack built.\n\nThis is the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the rooster that crowed in the morn\nthat woke the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the farmer sowing his corn\nthat kept the rooster that crowed in the morn\nthat woke the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.\n\nThis is the horse and the hound and the horn\nthat belonged to the farmer sowing his corn\nthat kept the rooster that crowed in the morn\nthat woke the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built.'def verse(verse_no):return '\n'.join(['This is ' + ' '.join(song[-verse_no-1].split()[2:]), '\n'.join(song[-verse_no:])]) if verse_no > 0 else 'This is the house that Jack built.'
​

答案10:

text = "This is the horse and the hound and the horn\nthat belonged to the farmer sowing his corn\nthat kept the rooster that crowed in the morn\nthat woke the priest all shaven and shorn\nthat married the man all tattered and torn\nthat kissed the maiden all forlorn\nthat milked the cow with the crumpled horn\nthat tossed the dog\nthat worried the cat\nthat killed the rat\nthat ate the malt\nthat lay in the house that Jack built."def rhyme():alls = text.split("\n")full = ""for i in range(len(alls)):full += verse(i)if i != len(alls)-1: full += "\n\n" return fulldef verse(verse_no):tmp = text.split("\n")[-verse_no-1:]first = tmp[0].split()first = first[first.index("the"):]whole = "This is "+" ".join(first)    return whole+"\n"+"\n".join(tmp[1:]) if len(tmp) > 1 else whole
​

景越Python基础训练营QQ群


欢迎各位同学加群讨论,一起学习,共同成长!

Python练习题答案: 杰克的家【难度:2级】--景越Python编程实例训练营,1000道上机题等你来挑战相关推荐

  1. Python练习题答案: 馏分类【难度:2级】--景越Python编程实例训练营,1000道上机题等你来挑战

    馏分类[难度:2级]: 答案1: # Something goes Here ...class Fraction:def __init__(self, numerator, denominator): ...

  2. Python练习题答案: IRR计算 - 盈利能力的评价【难度:2级】--景越Python编程实例训练营,1000道上机题等你来挑战

    IRR计算 - 盈利能力的评价[难度:2级]: 答案1: def irr(c):precision, guess, v, lastPositiveGuess, lastNegativeGuess = ...

  3. Python练习题答案: 分类新会员【难度:1级】--景越Python编程实例训练营,1000道上机题等你来挑战

    分类新会员[难度:1级]: 答案1: def openOrSenior(data):return ["Senior" if age >= 55 and handicap &g ...

  4. Python练习题答案: CIS 122#12中的构造【难度:1级】--景越Python编程实例训练营,1000道上机题等你来挑战

    CIS 122#12中的构造[难度:1级]: 答案1: # For your convenience, the following functions from previous challenges ...

  5. Python练习题答案: 转换货币II【难度:2级】--景越Python编程实例训练营,1000道上机题等你来挑战

    转换货币II[难度:2级]: 答案1: def solution(to,lst):dolSym, eurSym, power = ('', '€', -1) if to=='EUR' else ('$ ...

  6. Python练习题答案: 海盗!是大炮准备好了!?【难度:0级】--景越Python编程实例训练营,1000道上机题等你来挑战

    海盗!是大炮准备好了!?[难度:0级]: 答案1: def cannons_ready(gunners):return 'Shiver me timbers!' if 'nay' in gunners ...

  7. Python练习题答案: 摩门经【难度:2级】--景越Python编程实例训练营,1000道上机题等你来挑战

    摩门经[难度:2级]: 答案1: from math import log, ceil def mormons(starting_number, reach, target):return ceil( ...

  8. Python练习题答案: 财富通灵塔的乘驾【难度:3级】--景越Python编程实例训练营,1000道上机题等你来挑战

    财富通灵塔的乘驾[难度:3级]: 答案1: def ride_of_fortune(artifact, explorers):STATES = {'A': 'B', 'B': 'A'}DIRS = { ...

  9. Python练习题答案: 赛车#1:简化拖动赛【难度:1级】--景越Python编程实例训练营,1000道上机题等你来挑战

    赛车#1:简化拖动赛[难度:1级]: 答案1: def drag_race(length, anna, bob):a = length / anna.speed + anna.reaction_tim ...

最新文章

  1. 上面一个星星下面一个r_中国第一个王朝不是夏朝?山西出土一个破陶壶,上面俩字揭开谜题...
  2. JXOI2018做题笔记
  3. 【IDEA】怎么把idea的目录结构,以文本形式输出?
  4. 串联矩阵matlab代码,Matlab串联矩阵函数【horzcat】详细解析
  5. 纪中B组模拟赛总结(2020.2.22)
  6. php中des加密cbc模式,php中加密解密DES类的简单使用方法示例
  7. word 7桌面上的计算机图标是,怎么设置win7系统桌面图标都变成word图标的处理办法...
  8. GridMask:SOTA 数据增广方法,显著改进分类、检测、分割效果
  9. oracle full table scan,ORACLE优化之执行规划(1) - TABLE FULL SCAN/INDEX FULL SCAN
  10. 绕过限制,申请Google+
  11. 数字图像处理—美图秀秀:磨皮算法
  12. 大数据Hadoop(六):全网最详细的Hadoop集群搭建
  13. 最新最全论文合集——CCS 历年最佳论文汇总
  14. 简单新闻客户端APP设计
  15. keba驱动器_KEBA控制器说明书
  16. Neo4j 4.x 社区版数据导入及Spring-Data-Neo4j 5.x、6.x使用案例
  17. 异贝,通过移动互联网技术,为中小微实体企业联盟、线上链接、线上线下自定义营销方案推送。案例53
  18. 电脑无法连接WiFi,右下角显示红叉解决方法
  19. java ide的配置(idea)
  20. 深扒“亚稳态”的底裤,从MOS管到CMOS门电路,再到亚稳态分析

热门文章

  1. 华为是怎样研发的(4)——器件选型
  2. 多懂点SQL可以写出更好的接口
  3. 三相短路电流计算机算法的原理什么,三相短路电流的计算机算法
  4. AHA Music插件:超好用的听歌识曲搜索工具
  5. 用定时器设计门铃,按下按键时蜂鸣器发出叮咚的门铃声
  6. 职称计算机ppt,2017年职称计算机考试(PPT练习题大全)(3)
  7. 使用gif.js根据视频片段生成GIF图
  8. excel批量文件改名批量加后缀
  9. web前端html+css实现立体旋转相册(表白可用)
  10. 为什么 Flutter 是跨平台开发的终极之选