-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
57 lines (50 loc) · 1.45 KB
/
Copy pathcalculator.py
File metadata and controls
57 lines (50 loc) · 1.45 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
def get_nums():
print("What numbers would you like to enter, separate the numbers with a new line:")
num1 = float(input())
num2 = float(input())
return num1, num2
def another():
print("Would you like to do more math? y,n")
loop = input()
if loop.lower() == "y":
return True
else:
return False
def get_sign(first):
if first:
print("Hi this is a calculator\nEnter + - * / to choose what type of math you would like:")
return input()
else:
print("Enter + - * / to choose what type of math you would like:")
return input()
loop = True
first = True
while loop:
sign = str(get_sign(first))
if sign == "+":
num1, num2 = get_nums()
result = num1 + num2
result = str(result)
print("Result: " + result + "\n")
loop = another()
elif sign == "-":
num1, num2 = get_nums()
result = num1 - num2
result = str(result)
print("Result: " + result + "\n")
loop = another()
elif sign == "*":
num1, num2 = get_nums()
result = num1 * num2
result = str(result)
print("Result: " + result + "\n")
loop = another()
elif sign == "/":
num1, num2 = get_nums()
result = num1 / num2
result = str(result)
print("Result: " + result + "\n")
loop = another()
else:
print("Not a valid sign, please try again:\n")
first = False