-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculatorpy.py
94 lines (78 loc) · 2.11 KB
/
calculatorpy.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Watermark / Menu
print("""
Python Calculator
Assessment Task 2: Python Project 1
Written by Oisin Aeonn F2BE
""")
def Menu():
print("""
Menu:
1. Addition (+)
2. Subtraction (-)
3. Multiplication (*)
4. Division (/)
5. Exit
""")
def Math():
Menu_Selection = input("Input Operation Type: ")
Allowed_Choices = ("1", "2", "3", "4")
if Menu_Selection in Allowed_Choices:
Number_1 = int(input("Input First Value: "))
Number_2 = int(input("Input Second Value: "))
# Addition
if Menu_Selection == "1":
Total = Number_1 + Number_2
print(f"{Number_1} + {Number_2} = {Total}")
Restart()
# Subtraction
elif Menu_Selection == "2":
Total = Number_1 - Number_2
print(f"{Number_1} - {Number_2} = {Total}")
Restart()
# Multiplication
elif Menu_Selection == "3":
Total = Number_1 * Number_2
print(f"{Number_1} * {Number_2} = {Total}")
Restart()
# Division
elif Menu_Selection == "4":
if Number_2 == 0:
print("Cannot divide by zero")
Math()
Menu()
else:
Total = Number_1 / Number_2
print(f"{Number_1} / {Number_2} = {Total}")
Restart()
# Exit
elif Menu_Selection == "5":
print("Thank You For Using This Program!")
quit()
# Error
else:
print("""
Invalid Selection Input
Please Try Again
""")
Menu()
Math()
# Ask User If They Need To Calculate More
def Restart():
Calculate_Again = input("Calculate Again? (yes/no): ")
Calculate_Again.lower
if Calculate_Again == "yes":
Menu()
Math()
elif Calculate_Again == "no":
print("Thank You For Using This Program!")
quit()
# Error
else:
print("""
Invalid Selection Input
Please Try Again
""")
Restart()
# Runtime Sequence
Menu()
Math()