正剧开始:
星历2015年12月21日 08:57:14, 银河系厄尔斯星球中华帝国江南行省。
[工程师阿伟]正在和[机器小伟]走在去[人叫板老师]家的路上。不知不觉间,小伟已经学
完了[人叫板老师]给他的练气期第一层功法,所以他想尽快的拿到第二层功法。
08:58:09, 很快就来到了目的地,见到了[人叫板老师],阿伟和小伟说明了来意。
08:59:18, [人叫板老师]看了看小伟说:你能告诉我你都从第一层功法中学到了什么吗?
09:00:13, 小伟说,老师功法上列明的这些我都已经学会了。说着指了指下面的图。
09:01:15, [人叫板老师很满意,说:不过,我还要考考你,过关了就传你下一层功法,不
过关就继续回去修炼。
09:02:52, 老师又说:如果是别人还有很多的题要做,还有好多的试卷要考,不过考虑到
你这么聪明,就出两道题好了。于是[人叫板老师]出了两道题。
09:03:26, 第一题,生成下面这张图
小伟说:这张图的特点就是对角线上的数字是相同的,[行号+列号-1] = 格中数字。于是飞快地写了这样一段代码:
<span style="font-size:18px;">def digitTable(): for row in range(1, 11): for col in range(1, 11): print('{0:{width}}'.format(row + col - 1, width=3), end=' '); print('\n'); return;</span>结果是:
>>> 1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10 11 3 4 5 6 7 8 9 10 11 12 4 5 6 7 8 9 10 11 12 13 5 6 7 8 9 10 11 12 13 14 6 7 8 9 10 11 12 13 14 15 7 8 9 10 11 12 13 14 15 16 8 9 10 11 12 13 14 15 16 17 9 10 11 12 13 14 15 16 17 18 10 11 12 13 14 15 16 17 18 19
第二题,生成这一张图:
小伟飞快的做起了这题,不一会就做好了:
<span style="font-size:18px;">def addExpr(): for num1 in range(0,11): for num2 in range(0, 11): print('{0:{width}} + {1:{width}} = {2:{width}}'.format( num1, num2, num1+num2, width=2), end=' '); print('\n'); return;</span>
<span style="font-size:14px;">>>> 0 + 0 = 0, 0 + 1 = 1, 0 + 2 = 2, 0 + 3 = 3, 0 + 4 = 4, 0 + 5 = 5, 0 + 6 = 6, 0 + 7 = 7, 0 + 8 = 8, 0 + 9 = 9, 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 + 4 = 13, 9 + 5 = 14, 9 + 6 = 15, 9 + 7 = 16, 9 + 8 = 17, 9 + 9 = 18, 9 + 10 = 19, 10 + 0 = 10, 10 + 1 = 11, 10 + 2 = 12, 10 + 3 = 13, 10 + 4 = 14, 10 + 5 = 15, 10 + 6 = 16, 10 + 7 = 17, 10 + 8 = 18, 10 + 9 = 19, 10 + 10 = 20, </span><span style="font-size:18px;"> </span>
09:05:14, 从现在起,小伟就要进入练气期第二重的修炼啦。
本节到此结束,欲知后事如何,请看下回分解。