Skip to content

Commit

Permalink
Merge pull request #618 from JYunth/main
Browse files Browse the repository at this point in the history
Improve Calculator.py
  • Loading branch information
gantavyamalviya authored Oct 5, 2022
2 parents af2b074 + d62f68e commit 1d2ad71
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions Python/Calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ def multiply(num1, num2):
def divide(num1, num2):

return num1 / num2


# Function to return the remainder of the division operation

def modulus(num1, num2):

return num1 % num2

# Function to return the nearest quotient of the division operation

def floor(num1, num2):

return num1 // num 2


print("Please select operation -\n" \

Expand All @@ -34,46 +46,61 @@ def divide(num1, num2):

"3. Multiply\n" \

"4. Divide\n")
"4. Divide\n" \

"5. Remainder" \

"6. Quotient")


# Take input from the user

select = int(input("Select operations form 1, 2, 3, 4 :"))
select = int(input("Select operations from 1, 2, 3, 4, 5, 6 :"))


number_1 = int(input("Enter first number: "))

number_2 = int(input("Enter second number: "))


# The user has selected addition
if select == 1:

print(number_1, "+", number_2, "=",

add(number_1, number_2))


# The user has selected subtraction
elif select == 2:

print(number_1, "-", number_2, "=",

subtract(number_1, number_2))


# The user has selected multiplication
elif select == 3:

print(number_1, "*", number_2, "=",

multiply(number_1, number_2))


# The user has selected division
elif select == 4:

print(number_1, "/", number_2, "=",

divide(number_1, number_2))

# The user has selected the modulo operator
elif select == 5:

print(number_1, "%", number_2, "=", modulus(number_1, number_2))

# The user has selected the floor division operator
elif select == 6:

print(number_1, "//", number_2, "=", floor(number_1, number_2))

# The user has entered a number that is not in the list
else:

print("Invalid input")
print("Invalid operation. Please retry.")

0 comments on commit 1d2ad71

Please sign in to comment.