python猜数字游戏

来源:互联网 发布:杰洛特的母亲 知乎 编辑:程序博客网 时间:2024/05/23 01:20

无聊写个python猜数字游戏:

#!/usr/bin/env python# -*- coding: utf-8 -*-# created by fhqplzj on 2017/06/23 下午12:18import randomimport stringimport timedef 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: '))


原创粉丝点击