刚学Python时间不长,但也知道了一点,看别人的参考写了一个猜数字小游戏,也算是禹学于乐吧。


#!/usr/bin/env   python                                                         

#coding=utf-8

 

import random

 

secret = random.randint(1,100)

guess,tries = 0,0

 

print u"已经给出了一个1-99的数字"

 

while guess != secret and tries < 5:

        print u"请给出你猜的数字:"

        print

        guess_str = raw_input()

    

        g = int(guess_str)

 

        if g == secret:

                print u"waaaaa.....OK, 你猜对了。"

                break

        elif g < secret:

                print str(g),u"you are wrong. 太小了 "

        elif g > secret:

                print str(g),u"you are wrong. 太大了"

 

        tries += 1

 

else:

        print u"猜了5次都没猜到,智商有点捉急阿!!!"

        print u"想知道答案吗?求我呀~~hiahiahia"

        print

        print

        print

        print u"好吧这个数字就是:",str(secret)