Guest User

Untitled

a guest
Oct 29th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. from __future__ import division
  2. import random
  3.  
  4. def rand_numb():
  5.     return(random.randint(1, 10) for i in range(2))
  6.  
  7. def operators():
  8.     return \
  9.     {'*': lambda x, y: x * y,
  10.      '+': lambda x, y: x + y,
  11.      '/': lambda x, y: x / y,
  12.      '-': lambda x, y: x - y}
  13.  
  14. def calc_sum(fist,second,op,rand_op):
  15.     return op[rand_op](first,second)
  16.  
  17. if __name__ == '__main__':
  18.     op = operators()
  19.     first,second = rand_numb()
  20.     rand_op = random.choice(op.keys())
  21.     calc_sum = calc_sum(first,second,op,rand_op)
  22.     print '{} {} {} = {:.1f}'.format(first,rand_op,second,calc_sum)
Advertisement
Add Comment
Please, Sign In to add comment