### python 编程小实例（2） 四则运算小游戏

def main():
while True:
arithmetic()
try:
goon = raw_input('next(y/n)').strip()[0]
except IndexError:
continue
except (EOFError,IOError):
goon = n
if goon in 'nN':
break

if __name__ =='__main__':
main()

import  random
import operator

def arithmetic():
nums =[random.randint(1,100) for i in range(2)]
nums.sort(reverse=True)
op = random.choice('+-')
print 'op',op
result = ops[op](*nums)
print 'result',result
prompt = '%s%s%s='%(nums[0],op,nums[1])
tries = 1
while tries <= 3:
try:
except ValueError:
print 'input a number'
except (EOFError,IOError),e:
print 'Error',e
else:
tries +=1
else:

#!/usr/bin/env python
#coding:utf8

import random
import operator

def arithmetic():
nums =[random.randint(1,100) for i in range(2)]
nums.sort(reverse=True)
op = random.choice('+-')
print 'op',op
result = ops[op](*nums)
print 'result',result
prompt = '%s%s%s='%(nums[0],op,nums[1])
tries = 1
while tries <= 3:
try:
except ValueError:
print 'input a number'
except (EOFError,IOError),e:
print 'Error',e
else:
tries +=1
else:
def main():
while True:
arithmetic()
try:
goon = raw_input('next(y/n)').strip()[0]
except IndexError:
continue
except (EOFError,IOError):
goon = n
if goon in 'nN':
break

if __name__ =='__main__':
main()