1 #!/usr/bin/env python
2 #coding:utf-8
3 #猜数例程
4 import random
5
6 number = random.randint(1,101)
7
8 guess = 0
9 print("number = ",number)
10 while True:
11
12 num_input = input("please input one integer that is in 1 to 100:")
13 guess += 1
14
15 if not num_input.isdigit():
16 print("Please input interger.")
17 elif int(num_input) < 0 or int(num_input) >= 100:
18 print("The number should be in 1 to 100.")
19 else:
20 if number == int(num_input):
21 print("OK, you are good.It is only %d, then you successed." % guess)
22 break
23 elif number > int(num_input):
24 print("your number is more less.")
25 elif number < int(num_input):
26 print("your number is bigger.")
27 else:
28 print("There is something bad, I will not work")