2) Write a calculator history functionality in continuation of the above example and perform the multiplication, subtraction, division and square of the given numbers and store the result in calculator_history.txt file
1
Expert's answer
2011-08-04T12:31:35-0400
fout = open ("calculator_history.txt", "w")
def calc_mul (a, b): fout.write(str(a) + "*" + str(b) + "=" + str(a*b) + "\n") return a * b
def calc_add (a, b): fout.write(str(a) + "+" + str(b) + "=" + str(a+b) + "\n") return a + b
def calc_sub (a, b): fout.write(str(a) + "-" + str(b) + "=" + str(a-b) + "\n") return a - b
def calc_div (a, b): fout.write(str(a) + "/" + str(b) + "=" + str(a/b) + "\n") return a / b
def calc_square (a): fout.write(str(a) + "^2" + "=" + str(a*a) + "\n") return a * a
a, b, c, d = 10, 20, 30, 5
print( calc_square( calc_div( calc_mul( calc_sub(a,b), c ), d)))
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments