-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF4 - Calculator tast.py
71 lines (51 loc) · 1.96 KB
/
F4 - Calculator tast.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
#Defining The Calculator Operations And Their Functions.
def add(x,y):
return x + y
def subtract(x,y):
return x - y
def multiply(x,y):
return x * y
def divide(x,y):
return x / y
def power(x,y):
return x ** y
#Welcome & Instructions Text.
print("Welcome To Mark's Helpful Calculator!\nThe Operations That Are Available Are:")
print("1.Addition(+)\n2.Subtraction(-)\n3.Multiplication(*)\n4.Division(/)\n5.Exponent(^)")
input("\nPress Enter to Start")
#Defining The Calculation Function, Asking For The User's Input & Error Handling.
def calculate():
x = float(input("\nEnter Your First Number: "))
y = float(input("Enter Your Second Number: "))
operation = input("Enter Your Operation Of Choice: ")
if operation in ('+', '-', '*', '/', '^'):
if operation == '+':
Answ1 = add(x, y)
print(f"Answer: {x} + {y} = {Answ1}")
elif operation == '-':
Answ2 = subtract(x, y)
print(f"Answer: {x} - {y} = {Answ2}")
elif operation == '*':
Answ3 = multiply(x, y)
print(f"Answer: {x} x {y} = {Answ3}")
elif operation == '/':
Answ4 = divide(x, y)
print(f"Answer: {x} / {y} = {Answ4}")
elif operation == '^':
Answ5 = power(x, y)
print(f"Answer: {x} ^ {y} = {Answ5}")
else:
print("ERROR 'Invalid Operation'")
calculate()
rerun()
#Asking If The User Wants To Continue Or Stop Using The Calculator.
def rerun():
run_again = input("\nWould you like to calculate again?\nPlease Type Y for Yes or N for No: ")
if run_again.upper() == "Y":
calculate()
elif run_again.upper() == "N":
print("Good Luck!")
quit()
else:
rerun()
calculate()