python写的第一个简单小游戏-猜数字

 1 #Filename:game1.py
 2 
 3 guess=10
 4 running=True
 5 while running:
 6         try:
 7            answer=int(raw_input('Guess what i think:'))
 8         except:
 9             print 'Please input interga\n'
10             continue
11         
12         if answer<guess:
13                print 'Your answer is too small\n'
14                continue
15         elif answer>guess:
16                print 'Your answer is too large\n'
17                continue
18         else:
19                print 'BINGO'
20                break
21 
22 print '\nDone'

学习python有一段时间了,回头把第一章看到的猜数字游戏写了下,加入了捕获异常,更加的强壮。

posted @ 2014-08-08 15:03  熠然  阅读(319)  评论(0编辑  收藏  举报