某博主最近不知道该写什么文章,最近Python深得许多爬虫大佬的喜欢,于是某闲着么事干的博主就搜罗了一些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<rand):

print('*_* Lower than the answer')

else:

print('T_T Higher than the answer')

num=int(input('###Guess the number###\n'))

cnt=cnt+1

print('^_^ You get the answer with [%d] times'%cnt)

结语

引用别人的内容还写这么少,太过分了!
Python的学习过程是痛苦快乐的,希望你在今后的学习中学到更多好玩的知识。

引用内容:①风变编程&酱酱 ②简书&小天真_5eeb https://www.jianshu.com/p/0519365d27c8 侵删

最后修改:2019 年 12 月 29 日 03 : 33 PM
如果觉得我的文章对你有用,请随意赞赏