python有趣代码-python有趣的一行代码

python有趣的一行代码

程序员式表白

print(' '.join([''.join([('AndyLove'[(x-y)%8]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<=0 else' ')for x in range(-30,30)])for y in range(15,-15,-1)]))

一行显示乘法表

print(' '.join([' '.join(['%s*%s=%-2s' % (y,x,x*y) for y in range(1,x+1)]) for x in range(1,10)]))

一行显示迷宫

print(''.join(__import__('random').choice('╱╲') for i in range(50*24)))

一行代码输出Mandelbrot图像

print(' '.join([''.join(['*'if abs((lambda a:lambda z,c,n:a(a,z,c,n))(lambda s,z,c,n:z if n==0else s(s,z*z+c,c,n-1))(0,0.02*x+0.05j*y,40))<2else' 'for x in range(-80,20)]) for y in range(-20,20)]))

一行代码计算出1-100之间的素数

print(' '.join([str(item) for item in filter(lambda x: all(map(lambda p: x % p!= 0, range(2, x))), range(2, 101))]))

一行代码输出前100项斐波那契数列的值

print([x[0] for x in [ (a[i][0], a.append((a[i][1], a[i][0]+a[i][1]))) for a in ([[1,1]], ) for i in range(100) ]])

你可能感兴趣的:(python有趣代码-python有趣的一行代码)