-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.py
More file actions
70 lines (59 loc) · 1.8 KB
/
Copy pathCalculator.py
File metadata and controls
70 lines (59 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# imports
import math
# define functions
def addition(num1,num2):
return num1+num2
def subtraction(num1,num2):
return num1-num2
def multiplication(num1,num2):
return num1*num2
def division(num1,num2):
return num1/num2
def second_Power(enteredNumber):
return enteredNumber**2
def square_root(enteredNumber):
return math.sqrt(enteredNumber)
# Options for users to choose from
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. second_power")
print("6. square_root")
print("7. exit")
# Start loop.
while True:
# user input number
choice=input("choose operation: ")
# stop and exit program
if choice == '7':
print("Goodbye!")
break
# addition
if choice == '1':
num1=int((input("enter first number: ")))
num2=int((input("enter second number: ")))
print(num1, "+" ,num2, "=", addition(num1, num2))
# subtraction
if choice == '2':
num1=int((input("enter first number: ")))
num2=int((input("enter second number: ")))
print(num1, "-", num2, "=", subtraction(num1, num2))
# multiplication
if choice == '3':
num1=int((input("enter first number: ")))
num2=int((input("enter second number: ")))
print(num1, "*", num2, "=", multiplication(num1, num2))
# division
if choice == '4':
num1=int((input("enter first number: ")))
num2=int((input("enter second number: ")))
print(num1, "/", num2, "=", division(num1, num2))
# second_power
if choice =='5':
num3 = int(input("enter number: "))
print(str(num3)+"^2 =",second_Power(num3))
# square_root
if choice =='6':
num3 = int(input("enter number: "))
print("√",num3,"=",math.sqrt(num3))