python 猜数小游戏

#^_^ coding=gbk ^_^
import random
i = 0
while True:
    answer = random.randrange(0,100)
    enter_num = int(raw_input('请输入猜的数字(0-100): '))
    if enter_num <= 100 and enter_num >=0:
        if enter_num == answer:
            print '恭喜您,猜中了...!请继续!\n'
            continue
        else:
            i += 1
            print '您猜错了,您还有 %d 次机会\n ' % (6-i)
        if i > 5:
            print '您已经失去五次机会。。。。!!\n'
            break
    else:
        print '请输入一个规定的数值!!\n'

O(∩_∩)O~ 刚才看了一个博客,觉得听有意思的,然后自己写了一个!

你可能感兴趣的:(python猜数小游戏)