From b927d80df87b5b74322a6022d93145c8fa6ae87e Mon Sep 17 00:00:00 2001 From: Shivam23Thaman Date: Wed, 4 Aug 2021 15:15:43 +0530 Subject: [PATCH 1/7] added calculator file --- calculator.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 calculator.py diff --git a/calculator.py b/calculator.py new file mode 100644 index 0000000..9e5f2a7 --- /dev/null +++ b/calculator.py @@ -0,0 +1,49 @@ +# Program make a simple calculator + +# This function adds two numbers +def add(x, y): + return x + y + +# This function subtracts two numbers +def subtract(x, y): + return x - y + +# This function multiplies two numbers +def multiply(x, y): + return x * y + +# This function divides two numbers +def divide(x, y): + return x / y + + +print("Select operation.") +print("1.Add") +print("2.Subtract") +print("3.Multiply") +print("4.Divide") + +while True: + # Take input from the user + choice = input("Enter choice(1/2/3/4): ") + + # Check if choice is one of the four options + if choice in ('1', '2', '3', '4'): + num1 = float(input("Enter first number: ")) + num2 = float(input("Enter second number: ")) + + if choice == '1': + print(num1, "+", num2, "=", add(num1, num2)) + + elif choice == '2': + print(num1, "-", num2, "=", subtract(num1, num2)) + + elif choice == '3': + print(num1, "*", num2, "=", multiply(num1, num2)) + + elif choice == '4': + print(num1, "/", num2, "=", divide(num1, num2)) + break + else: + print("Invalid Input") + From e1fcfbecc6f8242e152fd29e45a2154e23be61c1 Mon Sep 17 00:00:00 2001 From: Shivam23Thaman Date: Wed, 4 Aug 2021 15:22:53 +0530 Subject: [PATCH 2/7] Removed files and modi sub --- calculator.py | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/calculator.py b/calculator.py index 9e5f2a7..c872524 100644 --- a/calculator.py +++ b/calculator.py @@ -5,45 +5,8 @@ def add(x, y): return x + y # This function subtracts two numbers -def subtract(x, y): - return x - y +def subtract(a, b): + return a - b -# This function multiplies two numbers -def multiply(x, y): - return x * y - -# This function divides two numbers -def divide(x, y): - return x / y - - -print("Select operation.") -print("1.Add") -print("2.Subtract") -print("3.Multiply") -print("4.Divide") - -while True: - # Take input from the user - choice = input("Enter choice(1/2/3/4): ") - - # Check if choice is one of the four options - if choice in ('1', '2', '3', '4'): - num1 = float(input("Enter first number: ")) - num2 = float(input("Enter second number: ")) - - if choice == '1': - print(num1, "+", num2, "=", add(num1, num2)) - - elif choice == '2': - print(num1, "-", num2, "=", subtract(num1, num2)) - - elif choice == '3': - print(num1, "*", num2, "=", multiply(num1, num2)) - - elif choice == '4': - print(num1, "/", num2, "=", divide(num1, num2)) - break - else: - print("Invalid Input") + From f8f1de4dc7efe9e38c42a68ec3b6b9d0043a4b4a Mon Sep 17 00:00:00 2001 From: Shivam23Thaman Date: Wed, 4 Aug 2021 15:49:36 +0530 Subject: [PATCH 3/7] added multiply --- calculator.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/calculator.py b/calculator.py index c872524..6342d5f 100644 --- a/calculator.py +++ b/calculator.py @@ -1,4 +1,4 @@ -# Program make a simple calculator +ef# Program make a simple calculator # This function adds two numbers def add(x, y): @@ -9,4 +9,7 @@ def subtract(a, b): return a - b - +def mul(a,b): + return a * b + + From 94d04eb0a08a3f98a2374e5c2804bf87504946c4 Mon Sep 17 00:00:00 2001 From: Shivam23Thaman Date: Wed, 4 Aug 2021 16:20:28 +0530 Subject: [PATCH 4/7] removed div --- calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calculator.py b/calculator.py index 6342d5f..921f1c1 100644 --- a/calculator.py +++ b/calculator.py @@ -11,5 +11,5 @@ def subtract(a, b): def mul(a,b): return a * b - + From 8d72fa477e21c481ffbcc10a8ad9c2054f8fc1be Mon Sep 17 00:00:00 2001 From: Shivam23Thaman Date: Wed, 4 Aug 2021 16:23:01 +0530 Subject: [PATCH 5/7] added div --- calculator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/calculator.py b/calculator.py index c872524..db82642 100644 --- a/calculator.py +++ b/calculator.py @@ -9,4 +9,6 @@ def subtract(a, b): return a - b +def div(a,b): + return a/b From a6e75e5b2358e8c90c43eade151656f5d8c1328d Mon Sep 17 00:00:00 2001 From: Shivam23Thaman Date: Wed, 4 Aug 2021 16:54:09 +0530 Subject: [PATCH 6/7] added mul to subtract --- calculator.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/calculator.py b/calculator.py index c872524..d10cc2e 100644 --- a/calculator.py +++ b/calculator.py @@ -7,6 +7,10 @@ def add(x, y): # This function subtracts two numbers def subtract(a, b): return a - b + +def mul(a,b): + return a*b + From 76a28f44414d83aa697d4c3f4abc40d44cc4f616 Mon Sep 17 00:00:00 2001 From: Shivam23Thaman Date: Wed, 4 Aug 2021 16:58:31 +0530 Subject: [PATCH 7/7] added div --- calculator.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/calculator.py b/calculator.py index d10cc2e..e982054 100644 --- a/calculator.py +++ b/calculator.py @@ -10,7 +10,9 @@ def subtract(a, b): def mul(a,b): return a*b - + +def div(a,b): + return a/b