猜数字游戏,,[Python]代码im
猜数字游戏,,[Python]代码im
[Python]代码
import randomdef run(): a=[] #存放4个数字 x=range(10) for i in range(4): a+=str(x.pop(random.randrange(10-i))) #从10个数字里选4个 b=set(a) #用于判断猜中几个数 end=True #开始猜循环 t=0 #累计猜的次数 while end: A=0 #数字位置都正确 C=0 #数字猜中数 while True: c=raw_input('input four number:') if c in ['i love you','love you','kiss you','miss you']: #作弊 print("Thank you! the answer is {0}".format(a)) continue elif len(c)!=4: print('Four number,please!') continue elif len(set(c))!=4: print('Four different number,ok?') continue else: break for i in range(4): if c[i]==a[i]: A+=1 if c[i] in b: C+=1 t+=1 if A==4: print("Congratulations!You've just got it after {0} times".format(t)) end=False #结束游戏 else: print("{0:2d}A{1:2d}B".format(A,C-A)) #给提示。(C-A即猜中但位置不对的数) if t==10: print("Are you tired?") if t==11: print("If you need help,just say'i love you' ^_^")run()
相关内容
- Python实现的Blowfish加解密,pythonblowfish,Blowfish加解密字
- 又是 web.py 页面执行计时,web.py页面执行计时,实现计时
- python code for solving eigenvalue problem by Jacobi’s method,eig
- python queue模块 消息队列,pythonqueue,#!/usr/local
- 使用python3的base64编解码实现字符串的简易加密解密,
- 输出金字塔形数字,输出金字塔形,[Python]代码i=
- python分割文件,,[Python]代码#!
- 卡饭论坛茶舍抢沙发第2版,茶舍沙发,[Python]代码#-
- 用正则表达式过滤掉文件中的指定邮箱地址,正则表达
- 数据字典 查询电话号码或地址,字典电话号码,查找电
评论关闭