Case5. Arithmetic operations on numbers are numbered as follows: 1 - addition, 2 - subtraction, 3 - multiplication, 4 - division. Given action number N (integer in the range 1-4) and real numbers A and B (B is not equal to 0). Execute the above action on the numbers and output the result.

Solution in Python 3:

import random

print("1 — addition, 2 — subtraction, 3 — multiplication, 4 — division")

i = random.randrange(1,5)
A = random.randrange(-10,10)
B = random.randrange(-10,10)
print("Operation number: ", i)
print("Number A: ", A)
print("Number B: ", B)
if B < 0:
B_str = "("+str(B)+")"
else:
B_str = str(B)
if i == 1:
print(A, "+", B_str, "=", A+B)
elif i == 2:
print(A, "-", B_str, "=", A-B)
elif i == 3:
print(A, "*", B_str, "=", A*B)
elif i == 4:
if B == 0:
print("Division by zero is undefined")
else:
print(A, "/", B_str, "=", A/B)