Program to Perform Calculator Function.

  1. def add(n1, n2):
  2.     return n1 + n2


  3. def subtract(n1, n2):
  4.     return n1 - n2


  5. def multiply(n1, n2):
  6.     return n1 * n2


  7. def divide(n1, n2):
  8.     return n1 / n2


  9. def sqaure_root(num1):
  10.     n = num1 ** 0.5
  11.     print(f"Current Result : {round(n, 1)} \n End of calculation")


  12. def sqaure(num1):
  13.     n = num1 ** 2
  14.     print(f"Current Result : {round(n, 1)} \n End of calculation")


  15. def display():
  16.     print(" + \n - \n * \n / \n Square Root(sr) for one value \n Sqaure(s) for one value\n ")


  17. op_list = ['+', '-', '*', '/', 's', 'sr']


  18. def calculation_operation():
  19.     num1 = int(input(" Enter a First number : "))
  20.     display()
  21.     def further(num1):
  22.         flag = True
  23.         while flag:
  24.             op = input(" Choose operator from above : ")
  25.             if op == 's':
  26.                 sqaure(num1)
  27.                 break
  28.             elif op == 'sr':
  29.                 sqaure_root(num1)
  30.                 break
  31.             num2 = int(input(" Enter next number : "))
  32.             result = 0
  33.             if op == '+':
  34.                 result = add(num1, num2)
  35.             elif op == '-':
  36.                 result = subtract(num1, num2)
  37.             elif op == '*':
  38.                 result = multiply(num1, num2)
  39.             elif op == '/':
  40.                 result = divide(num1, num2)
  41.             else:
  42.                 print("You Select Wrong Option")
  43.                 break
  44.             if input(f" Do you want to continue [ {round(result, 1)} ] as result? (y \ n) : ").lower() == 'y':
  45.                 print(f" Current Result : {round(result, 1)} \n End of calculation")
  46.                 flag = False
  47.             else:
  48.                 n1 = result
  49.                 further(n1)

  50.     further(num1)


  51. print(" Program to perform Calculator Operations\n")
  52. print('\n-----------------------------------------\n')
  53. calculation_operation()
  54.  

Output :






Comments

Popular posts from this blog

Turtle Crossing Project Using Turtle modules.

Check for Prime Number either between 1-100 or user-given