python上手还真的是不难,呵。写了个猜数字的小游戏。
==================================================
#_*_ coding: utf-8 _*_
import random
print '''
===================================
[猜数字游戏开始]'''
def guessNum() :
~goalNum = random.randint(0,99)
~tip = "\n请您猜一个数字,此数字介于0~99之间:"
~guessCount = 0
~while True :
~~yourNum = raw_input(tip)
~~yourNum = int(yourNum)
~~tip = "请您再猜:"
~~guessCount += 1
~~if yourNum < goalNum :
~~~print ">> (您猜的数小了 T_T)"
~~elif yourNum > goalNum :
~~~print ">> (您猜的数大了 T_T)"
~~else :
~~~print ">> (恭喜您猜中了 ^0^ , 您共猜了 %s 次猜中了结果)" % guessCount
~~~break
~continueFlag = raw_input("游戏结束。您还想再玩一次吗? y | n : ")
~if continueFlag == "y" :
~~guessNum()
~elif continueFlag == "n" :
~~print "游戏结束,谢谢您的参与。\n==================================="
~else :
~~print "请您输入y或n"
guessNum()
==================================================
截图: