python猜数字游戏
2017-06-27 19:55
309 查看
无聊写个python猜数字游戏:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# created by fhqplzj on 2017/06/23 下午12:18
import random
import string
import time
def game(target):
possibles = string.letters + string.digits + ' '
current = [random.choice(possibles) for _ in range(len(target))]
flag = False
while not flag:
print ''.join(current)
flag = True
for i in range(len(target)):
if current[i] != target[i]:
current[i] = random.choice(possibles)
flag = False
time.sleep(0.02)
if __name__ == '__main__':
game(raw_input('input target: '))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# created by fhqplzj on 2017/06/23 下午12:18
import random
import string
import time
def game(target):
possibles = string.letters + string.digits + ' '
current = [random.choice(possibles) for _ in range(len(target))]
flag = False
while not flag:
print ''.join(current)
flag = True
for i in range(len(target)):
if current[i] != target[i]:
current[i] = random.choice(possibles)
flag = False
time.sleep(0.02)
if __name__ == '__main__':
game(raw_input('input target: '))
相关文章推荐
- python GUI 猜数字游戏
- python 猜数字游戏
- Python_猜数字游戏_初次尝试(遗留问题:猜错后程序自动循环执行未实现)---加入循环搞定
- java & python猜数字游戏对比
- Python学习笔记(五)猜数字游戏(while)
- Python 入门学习--猜数字游戏
- Python数字游戏
- python 猜数字游戏
- python小练习8:猜数字游戏
- 猜数字游戏——初探 python 界面编程
- python基础-猜数字游戏
- Python 猜数字游戏,解决变量类型异常问题
- 用Python写一个猜数字游戏
- Python: 渐进猜数字游戏 <7> 数字比较 与 猜数字游戏V0.1版
- python编写的bmi体重指数计算器、出租车费用计算器、个税计算器、猜数字游戏
- python练手程序(1)—— 猜数字游戏
- python魔法师solo数字游戏
- python猜数字游戏
- 用Python玩转数据 Data Processing Using Python 南京大学笔记一:Python猜数字游戏
- python比数字游戏