某博主最近不知道该写什么文章,最近Python深得许多爬虫大佬的喜欢,于是某闲着么事干的博主就搜罗了一些Python趣味代码。
No.1 爱心
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)]))
No.2 99乘法表
print('\n'.join([' '.join(['%s*%s=%-2s' % (y, x, x*y) for y in range(1, x+1)]) for x in range(1, 10)]))
No.3 石头剪刀布
# coding=utf-8
import random
# 获胜次数
win_times = 0
while win_times <= 2:
player = input('请输入:剪刀(0) 石头(1) 布(2):')
player = int(player)
computer = random.randint(0,2)
if ((player == 0) and (computer == 2)) or ((player ==1) and (computer == 0)) or ((player == 2) and (computer == 1)):
win_times += 1
print('获胜,哈哈,你太厉害了')
elif player == computer:
print('平局,要不再来一局')
else:
print('输了,不要走,洗洗手接着来,决战到天亮')
No.4 猜数字
#!/usr/local/bin/python3
import random
bot=int(input('Set range bottom\n'))
top=int(input('Set range top\n'))
rand=random.randint(bot,top)
print ('Random number in ['+str(bot)+','+str(top)+'] generated!')
num=int(input('###Guess the number###\n'))
cnt=1
while (num!=rand):
if (num
结语
引用别人的内容还写这么少,太过分了!
Python的学习过程是痛苦快乐的,希望你在今后的学习中学到更多好玩的知识。
此处评论已关闭