Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import division
- import random
- def rand_numb():
- return(random.randint(1, 10) for i in range(2))
- def operators():
- return \
- {'*': lambda x, y: x * y,
- '+': lambda x, y: x + y,
- '/': lambda x, y: x / y,
- '-': lambda x, y: x - y}
- def calc_sum(fist,second,op,rand_op):
- return op[rand_op](first,second)
- if __name__ == '__main__':
- op = operators()
- first,second = rand_numb()
- rand_op = random.choice(op.keys())
- calc_sum = calc_sum(first,second,op,rand_op)
- print '{} {} {} = {:.1f}'.format(first,rand_op,second,calc_sum)
Advertisement
Add Comment
Please, Sign In to add comment