# Untitled

a guest
May 20th, 2019
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import math
2. import sys
3.
4. #Functions for the operations
6.     return num1 + num2
7.
8. def subtract(num1, num2):
9.     return num1 - num2
10.
11. def multiply(num1, num2):
12.     return num1 * num2
13.
14. def divide(num1, num2):
15.     return num1 / num2
16.
17. def expo(num1, num2):
18.     return num1 ** num2
19.
20. #The calculating function
21. def calc():
22.     print("Select an operator:")
24.     print("2.Subtract")
25.     print("3.Multiply")
26.     print("4.Divide")
27.     print("5.Expo")
28.     print("6.Root")
29.     select = int(input())
30.     if select >=1 and select <=6:
31.         if select == int(6):
32.             print("Enter a number...")
33.             root = int(float(input()))
34.             print("√", root,"=", math.sqrt(root))
35.         else:
36.             print("Enter the first number...")
37.             num1 = int(float(input()))
38.             print("Enter the second number...")
39.             num2 = int(float(input()))
40.             if select == int(1):
42.             elif select == int(2):
43.                 print(num1, "-",num2,"=", subtract(num1, num2))
44.             elif select == int(3):
45.                 print(num1, "*",num2,"=",  multiply(num1, num2))
46.             elif select == int(4):
47.                 print(num1, "/",num2,"=", divide(num1, num2))
48.             elif select == int(5):
49.                 print(num1, "**",num2,"=", expo(num1, num2))
50.     else:
51.         print("Invalid input!")
52.
53.
54. #The main function which use a while loop
55. def main():
56.     while True:
57.         calc()
58.         print('\nCalculation finished. Do another? (Y/N)')
59.         selector = input()
60.         if selector.lower() == 'n':
61.             break
62.
63.
64. #About the script, here I use the main function
65. print("This is a simple calculator on python.")
66. main()
RAW Paste Data