-
Notifications
You must be signed in to change notification settings - Fork 2
/
calc.py
executable file
·60 lines (57 loc) · 1.77 KB
/
calc.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
#!/usr/bin/env python3
__author__ = "Jugal Kishore"
__version__ = "1.1"
print("///A Simple Calculator///")
while 1:
num_a = input("\nEnter First Number: ")
num_b = input("\nEnter Second Number: ")
print("\nOptions: -")
print("+ for Addition")
print("- for Substraction")
print("* for Multiplication")
print("/ for Division")
print("% for Modulus")
print("Anything else to exit!")
choice = input("\nChoice: ")
if choice == "+":
print(
"\nAddition of {0} and {1} is = {2}".format(
num_a, num_b, float(num_a) + float(num_b)
)
)
elif choice == "-":
print(
"\nSubtraction of {0} and {1} is = {2}".format(
num_a, num_b, float(num_a) - float(num_b)
)
)
elif choice == "*":
print(
"\nMultiplication of {0} and {1} is = {2}".format(
num_a, num_b, float(num_a) * float(num_b)
)
)
elif choice == "/":
if num_b == "0":
print("\nYou can't divide '{0}' by zero.".format(num_a))
else:
print(
"\nDivison of {0} and {1} is = {2}".format(
num_a, num_b, float(num_a) / float(num_b)
)
)
elif choice == "%":
if num_b == "0":
print("\nYou can't divide '{0}' by zero.".format(num_a))
else:
print(
"\nModulus of {0} and {1} is = {2}".format(
num_a, num_b, round(float(num_a) % float(num_b), 3)
)
)
else:
print("Uh-Oh, you decided to exit.")
print("Exiting!")
break
print("\nCreated by Jugal Kishore -- 2020")
# Run it online at https://python.jugalkishore.repl.run/