圆月山庄资源网 Design By www.vgjia.com

本文实例讲述了python简单猜数游戏。分享给大家供大家参考。具体实现方法如下:

#!/usr/bin/env python
import random
number = random.randint(0,100)
print "Hello,Number guessing Game: betwween 0 and 100 inclusive."
guessString = raw_input("guess a number: ")
guess = int(guessString)
while 0 <= guess <= 100:
  if guess > number:
    print "Guessed Too High,please guess again!."
  elif guess < number:
    print "Guessed Too Low,please guess again!."
  else:
    print "You guessed it. The number was:",number
    break
  guessString = raw_input("Guess a number: ")
  guess = int(guessString)
else:
  print "Your guess was not between 0 and 100,the game is over,the number was:",number

希望本文所述对大家的Python程序设计有所帮助。

标签:
python,猜数游戏

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com