45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:python如何实现猜数游戏?python猜数游戏的实例分享

python如何实现猜数游戏?python猜数游戏的实例分享

2015-07-26 05:49:04 来源:www.45fan.com 【

python如何实现猜数游戏?python猜数游戏的实例分享

本文实例讲述了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程序设计有所帮助。


本文地址:http://www.45fan.com/a/question/15690.html
Tags: python 简单 猜数
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部