from random import randint
num=randint(1,100)
print’guess what I think?’
bingo=False
while bingo==False:
answer=input()
if answer<num:
print'too small!'
if answer>num:
print'too big!'
if answer==num:
print'BINGO!'
bingo=True
运行结果
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type “copyright”, “credits” or “license()” for more information.
================================ RESTART ================================
guess what I think?
12
too small!
55
too big!
33
too big!
22
too small!
25
too big!
23
BINGO!