Answer to Question #3392 in Python for mukunda

Question #3392
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)))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS