Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import sys
- #Functions for the operations
- def add(num1, num2):
- return num1 + num2
- def subtract(num1, num2):
- return num1 - num2
- def multiply(num1, num2):
- return num1 * num2
- def divide(num1, num2):
- return num1 / num2
- def expo(num1, num2):
- return num1 ** num2
- #The calculating function
- def calc():
- print("Select an operator:")
- print("1.Add")
- print("2.Subtract")
- print("3.Multiply")
- print("4.Divide")
- print("5.Expo")
- print("6.Root")
- select = int(input())
- if select >=1 and select <=6:
- if select == int(6):
- print("Enter a number...")
- root = int(float(input()))
- print("√", root,"=", math.sqrt(root))
- else:
- print("Enter the first number...")
- num1 = int(float(input()))
- print("Enter the second number...")
- num2 = int(float(input()))
- if select == int(1):
- print(num1, "+",num2,"=", add(num1, num2))
- elif select == int(2):
- print(num1, "-",num2,"=", subtract(num1, num2))
- elif select == int(3):
- print(num1, "*",num2,"=", multiply(num1, num2))
- elif select == int(4):
- print(num1, "/",num2,"=", divide(num1, num2))
- elif select == int(5):
- print(num1, "**",num2,"=", expo(num1, num2))
- else:
- print("Invalid input!")
- #The main function which use a while loop
- def main():
- while True:
- calc()
- print('\nCalculation finished. Do another? (Y/N)')
- selector = input()
- if selector.lower() == 'n':
- break
- #About the script, here I use the main function
- print("This is a simple calculator on python.")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement