一行Python代码画心型
一行Python代码画心型
1、画I组成的心型代码:
print('\n'.join([''.join([('I'[(x-y) % len('I')]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(30, -30, -1)]))
2、画Love组成的心型代码:
print('\n'.join([''.join([('Love'[(x-y) % len('Love')]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(30, -30, -1)]))
3、画You组成的心型代码:
print('\n'.join([''.join([('You'[(x-y) % len('You')]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(30, -30, -1)]))
4、画Raven组成的心型代码:
print('\n'.join([''.join([('Raven'[(x-y) % len('Raven')]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(30, -30, -1)]))