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
'
10             continue
11         
12         if answer<guess:
13                print 'Your answer is too small
'
14                continue
15         elif answer>guess:
16                print 'Your answer is too large
'
17                continue
18         else:
19                print 'BINGO'
20                break
21 
22 print '
Done'

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

原文地址:https://www.cnblogs.com/liyiran/p/3899393.html