代码清单1-2 猜数游戏

import random
secret=random.randint(1,100) #从1~100中产生一个随机数
guess=0
tries=0
print"Hi peng ! I'm shanshan, and I have a secret!"
print "It is a number from 1 to 99.I'll give you 6 tries."

while guess!=secret and tries<6:
     guess=input("what's your guess: ")
     if guess<secret:
                 print "Too low,ye scurvy dog!"
                 
     elif guess>secret:
                 print "Too high,landlubber!"
     tries=tries + 1
if guess==secret:
      print "Avast! you got it!Found my secret !you did it!"
                 
else:
      print "No more guess!Better luck next time,peng!"
      print "The secret number was:",secret


运行结果:

代码清单1-2 猜数游戏_第1张图片

你可能感兴趣的:(代码清单1-2 猜数游戏)