-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_5.py
51 lines (47 loc) · 1.56 KB
/
project_5.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
# simple calculator.
# Use the concept of buffer memory.
print("-------------------Calculator-------------------")
buffer = 0
n1 = float(input("Enter the first number : ")) # local varible but making global by passing it to main() function.
def add(n1,q) : # q is formal parameter for n2
buffer = n1 + q
return buffer
def substract(n1,q) :
buffer = n1 - q
return buffer
def multiply(n1,q) :
buffer = n1*q
return buffer
def divide(n1,q) :
buffer = n1/q
return buffer
def main(n1) :
operation = input("Enter the arithmetic operation : ")
n2 = float(input("Enter the second number : "))
if operation == "+" :
buffer=add(n1,n2)
print(f"{n1}+{n2}={buffer}")
elif operation == "-" :
buffer = substract(n1,n2)
print(f"{n1}-{n2}={buffer}")
elif operation == "*" :
buffer = multiply(n1,n2)
print(f"{n1}*{n2}={buffer}")
elif operation == "/" :
buffer = divide(n1,n2)
print(f"{n1}/{n2}={buffer}")
else :
print("Please choose a valid operator .")
main(n1)
choice = input(f"Type 'Yes' to continue with the output {buffer},'New' to start with the new calculation , or 'No' to exit ")
if choice == "Yes" :
n1 = buffer
main(n1)
elif choice == "New" :
buffer = 0
n1 = float(input("Enter the first number : ")) # redefination of the n1 for the new calculation.
main(n1)
elif choice == "No" :
print("Thank You for the visit !!!!!!")
print("-------------------Calculator-------------------")
main(n1)