Python 猜数字
闲着无聊,不想学习,不想动脑子,就花二十分钟写了个脑残的猜数字......还玩了一会儿,复习下循序渐进的思维。
Step 1 输入一个数
#-*-coding:UTF-8 -*-#BiangHoo OCT 1 2013import randomdef GuessNumber(guess,genNum,var): var +=1 if guess == genNum: print ("Congraduation!! you win") else: print ("the number you guess is ",end='')#不换行输出的做法 if(guess>genNum):#给出提示,猜测数值过大或过小 print("too Big !!") else: print("too Small !!") if var == 3:#如果猜测次数等于三次,游戏结束 print ("You Lose,Sucker,HaHaHaHa...") return g = input("please input a number:") guess = int(g) GuessNumber(guess,genNum,var) print ("Hello,Welcome to the Guess Number(0--20) Game,You have three shots,Good Luck")genNum = random.randint(1,20)#获得随机整数#print(genNum)var = 0#记录猜测次数g = input("please input a number:")guess = int(g)GuessNumber(guess,genNum,var)print("Game Over!!")