-
Notifications
You must be signed in to change notification settings - Fork 4
/
Calculator.py
73 lines (60 loc) · 2.12 KB
/
Calculator.py
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
71
72
73
def main():
while True:
print("Calculator")
print('''For:
Division press /
Exponent press **
Integral Division press //
Multiplication press *
Modulus (Remainder) press %
Subtraction press -
Addition press +''')
operation = input("Your response: ")
while operation not in ['/', '**', '//', '*', '%', '-', '+']:
print("Invalid input please try again!")
operation = input("Your response: ")
while True:
Num_1 = input("Enter first the number: ")
try:
Num_1 = float(Num_1)
break
except:
print("Invalid input please try again!")
while True:
Num_2 = input("Enter second the number: ")
try:
Num_2 = float(Num_2)
break
except:
print("Invalid input please try again!")
# Difference
if operation == '-':
print(f"Difference of {Num_1} and {Num_2} is {Num_1-Num_2}.")
# Division
elif operation == '/':
print(f"Division of {Num_1} and {Num_2} is {Num_1/Num_2}.")
# Exponential
elif operation == '**':
print(f"{Num_1} to the power {Num_2} is {Num_1**Num_2}.")
# Floor division
elif operation == '//':
print(f"Floor division of {Num_1} and {Num_2} is {Num_1//Num_2}.")
# Modulus
elif operation == '%':
print(
f"Modulus (Remainder) of {Num_1} and {Num_2} is {Num_1%Num_2}.")
# Multiplication
elif operation == '*':
print(f"Multiplication of {Num_1} and {Num_2} is {Num_1*Num_2}.")
# Summation
elif operation == "+":
print(f"Sum of {Num_1} and {Num_2} is {Num_1+Num_2}.")
# Program looping
Again = None
while Again not in ['y', 'n']:
Again = input(
"Do you want to run this feature again (y/n)? ").lower()
if Again != 'y':
break
if __name__ == '__main__':
main()