Skip to main content
Program to Perform Calculator Function.
- def add(n1, n2):
- return n1 + n2
- def subtract(n1, n2):
- return n1 - n2
- def multiply(n1, n2):
- return n1 * n2
- def divide(n1, n2):
- return n1 / n2
- def sqaure_root(num1):
- n = num1 ** 0.5
- print(f"Current Result : {round(n, 1)} \n End of calculation")
- def sqaure(num1):
- n = num1 ** 2
- print(f"Current Result : {round(n, 1)} \n End of calculation")
- def display():
- print(" + \n - \n * \n / \n Square Root(sr) for one value \n Sqaure(s) for one value\n ")
- op_list = ['+', '-', '*', '/', 's', 'sr']
- def calculation_operation():
- num1 = int(input(" Enter a First number : "))
- display()
- def further(num1):
- flag = True
- while flag:
- op = input(" Choose operator from above : ")
- if op == 's':
- sqaure(num1)
- break
- elif op == 'sr':
- sqaure_root(num1)
- break
- num2 = int(input(" Enter next number : "))
- result = 0
- if op == '+':
- result = add(num1, num2)
- elif op == '-':
- result = subtract(num1, num2)
- elif op == '*':
- result = multiply(num1, num2)
- elif op == '/':
- result = divide(num1, num2)
- else:
- print("You Select Wrong Option")
- break
- if input(f" Do you want to continue [ {round(result, 1)} ] as result? (y \ n) : ").lower() == 'y':
- print(f" Current Result : {round(result, 1)} \n End of calculation")
- flag = False
- else:
- n1 = result
- further(n1)
- further(num1)
- print(" Program to perform Calculator Operations\n")
- print('\n-----------------------------------------\n')
- calculation_operation()
-
Output :
Popular posts from this blog
Comments
Post a Comment