赞
踩
这是一个Python3.11及以上版本的实战练习
首先要知道,全屏python一行最多能装237个0,那以237作为一行的字符数非常恰当
我们先要设置出长和宽(不用)
将宽设为50是我的选择,当然你也可以改
那么需要设置50个列表(或集合)
- l1 = [0] * 237
- l2 = [0] * 237
- l3 = [0] * 237
- l4 = [0] * 237
- l5 = [0] * 237
- l6 = [0] * 237
- l7 = [0] * 237
- l8 = [0] * 237
- l9 = [0] * 237
- l10 = [0] * 237
- l11 = [0] * 237
- l12 = [0] * 237
- l13 = [0] * 237
- l14 = [0] * 237
- l15 = [0] * 237
- l16 = [0] * 237
- l17 = [0] * 237
- l18 = [0] * 237
- l19 = [0] * 237
- l20 = [0] * 237
- l21 = [0] * 237
- l22 = [0] * 237
- l23 = [0] * 237
- l24 = [0] * 237
- l25 = [0] * 237
- l26 = [0] * 237
- l27 = [0] * 237
- l28 = [0] * 237
- l29 = [0] * 237
- l30 = [0] * 237
- l31 = [0] * 237
- l32 = [0] * 237
- l33 = [0] * 237
- l34 = [0] * 237
- l35 = [0] * 237
- l36 = [0] * 237
- l37 = [0] * 237
- l38 = [0] * 237
- l39 = [0] * 237
- l40 = [0] * 237
- l41 = [0] * 237
- l42 = [0] * 237
- l43 = [0] * 237
- l44 = [0] * 237
- l45 = [0] * 237
- l46 = [0] * 237
- l47 = [0] * 237
- l48 = [0] * 237
- l49 = [0] * 237
- l50 = [0] * 237
好了,现在长和宽都有了,终于可以构造索引器(必须要的,不然你在编写patch的时候就会有困难)了
都说了版本是3.11及以上,那么有match...case的python就好弄了
在这里,我们将使用def语句
- def ln(num):
- match num:
- case 1:
- return l1
- case 2:
- return l2
- case 3:
- return l3
- case 4:
- return l4
- case 5:
- return l5
- case 6:
- return l6
- case 7:
- return l7
- case 8:
- return l8
- case 9:
- return l9
- case 10:
- return l10
- case 11:
- return l11
- case 12:
- return l12
- case 13:
- return l13
- case 14:
- return l14
- case 15:
- return l15
- case 16:
- return l16
- case 17:
- return l17
- case 18:
- return l18
- case 19:
- return l19
- case 20:
- return l20
- case 21:
- return l21
- case 22:
- return l22
- case 23:
- return l23
- case 24:
- return l24
- case 25:
- return l25
- case 26:
- return l26
- case 27:
- return l27
- case 28:
- return l28
- case 29:
- return l29
- case 30:
- return l30
- case 31:
- return l31
- case 32:
- return l32
- case 33:
- return l33
- case 34:
- return l34
- case 35:
- return l35
- case 36:
- return l36
- case 37:
- return l37
- case 38:
- return l38
- case 39:
- return l39
- case 40:
- return l40
- case 41:
- return l41
- case 42:
- return l42
- case 43:
- return l43
- case 44:
- return l44
- case 45:
- return l45
- case 46:
- return l46
- case 47:
- return l47
- case 48:
- return l48
- case 49:
- return l49
- case 50:
- return l50
- case _:
- print('Not found the list.')
我还在后面加了个错误提示(在编辑patch时有帮助)
当然,屏幕还是必不可少的元素之一,编写它最好用的语句就是for和print
首先要遍历长,而长的索引是ln,所以要用range
可编写出以下代码:
for w in range(1,51):
这样,我们就获得了1至50的所有数
那么这是要干吗呢?当然是用上ln函数啦!!!
我们要用for函数遍历ln函数索引出来的列表
那么就可以这样:
for cell in ln(w):
好了,现在每个字符我们都了解清楚了,它们就可以用print写出来了
全部代码:
- for w in range(1,51):
- for cell in ln(w):
- print(cell, end="")
但是请注意,他最后一个字符后面不会换行,若屏幕缩小,细胞就会错位,所以,要在第二个for后面加else:
- for cell in ln(w):
- print(cell, end="")
- else:
- print()
本博客介绍了在python中构建生命游戏基础框架和屏幕的方法,虽然有可能有问题
全部代码:
- l1 = [0] * 237
- l2 = [0] * 237
- l3 = [0] * 237
- l4 = [0] * 237
- l5 = [0] * 237
- l6 = [0] * 237
- l7 = [0] * 237
- l8 = [0] * 237
- l9 = [0] * 237
- l10 = [0] * 237
- l11 = [0] * 237
- l12 = [0] * 237
- l13 = [0] * 237
- l14 = [0] * 237
- l15 = [0] * 237
- l16 = [0] * 237
- l17 = [0] * 237
- l18 = [0] * 237
- l19 = [0] * 237
- l20 = [0] * 237
- l21 = [0] * 237
- l22 = [0] * 237
- l23 = [0] * 237
- l24 = [0] * 237
- l25 = [0] * 237
- l26 = [0] * 237
- l27 = [0] * 237
- l28 = [0] * 237
- l29 = [0] * 237
- l30 = [0] * 237
- l31 = [0] * 237
- l32 = [0] * 237
- l33 = [0] * 237
- l34 = [0] * 237
- l35 = [0] * 237
- l36 = [0] * 237
- l37 = [0] * 237
- l38 = [0] * 237
- l39 = [0] * 237
- l40 = [0] * 237
- l41 = [0] * 237
- l42 = [0] * 237
- l43 = [0] * 237
- l44 = [0] * 237
- l45 = [0] * 237
- l46 = [0] * 237
- l47 = [0] * 237
- l48 = [0] * 237
- l49 = [0] * 237
- l50 = [0] * 237
- def ln(num):
- match num:
- case 1:
- return l1
- case 2:
- return l2
- case 3:
- return l3
- case 4:
- return l4
- case 5:
- return l5
- case 6:
- return l6
- case 7:
- return l7
- case 8:
- return l8
- case 9:
- return l9
- case 10:
- return l10
- case 11:
- return l11
- case 12:
- return l12
- case 13:
- return l13
- case 14:
- return l14
- case 15:
- return l15
- case 16:
- return l16
- case 17:
- return l17
- case 18:
- return l18
- case 19:
- return l19
- case 20:
- return l20
- case 21:
- return l21
- case 22:
- return l22
- case 23:
- return l23
- case 24:
- return l24
- case 25:
- return l25
- case 26:
- return l26
- case 27:
- return l27
- case 28:
- return l28
- case 29:
- return l29
- case 30:
- return l30
- case 31:
- return l31
- case 32:
- return l32
- case 33:
- return l33
- case 34:
- return l34
- case 35:
- return l35
- case 36:
- return l36
- case 37:
- return l37
- case 38:
- return l38
- case 39:
- return l39
- case 40:
- return l40
- case 41:
- return l41
- case 42:
- return l42
- case 43:
- return l43
- case 44:
- return l44
- case 45:
- return l45
- case 46:
- return l46
- case 47:
- return l47
- case 48:
- return l48
- case 49:
- return l49
- case 50:
- return l50
- case _:
- print('Not found the list.')
- for w in range(1,51):
- for cell in ln(w):
- print(cell, end="")
- else:
- print()
输出:
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。