# Random Math

I was telling the kids how fast computers are, and to demonstrate I wrote this Python program to do simple multiplication, division, addition, and subtraction.

``````from random import random as rand
from random import choice
def randmath():
ops = {'+': 31, '-': 32, '*': 16, '/': 32}
operator = choice([i for i in ops.keys()])
scope = 1 << ops[operator]
num1 = int(rand()*scope)
num2 = int(rand()*scope)
mathstring = "{} {} {}".format(num1, operator, num2)
result = eval( mathstring )
print(mathstring , "=", result)

while True: randmath()
``````

Since that scrolls by so quickly, you may want to try this version, which pauses two seconds between calculations.

``````from random import random as rand
from random import choice
from time import sleep
def randmath():
ops = {'+': 31, '-': 32, '*': 16, '/': 32}
operator = choice([i for i in ops.keys()])
scope = 1 << ops[operator]
num1 = int(rand()*scope)
num2 = int(rand()*scope)
mathstring = "{} {} {}".format(num1, operator, num2)
result = eval( mathstring )
print(mathstring , "=", result)

while True:
randmath()
sleep(2)
``````

To get them all nicely tiled like that, right-click on the taskbar and select “Show windows stacked”