脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python简单猜数游戏实例

python简单猜数游戏实例

2020-07-21 10:33pythonstart Python

这篇文章主要介绍了python简单猜数游戏,涉及Python随机数及流程控制的相关技巧,需要的朋友可以参考下

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/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程序设计有所帮助。

延伸 · 阅读

精彩推荐