Computer Science, asked by kunjika158, 5 months ago

Write a Python program to make a calculater.

a) Input two numbers.

b) Apply Arithmetic operators (+, - ,*, /, % ,//, **)

Answers

Answered by Equestriadash
30

while True:

   print("1. Addition")

   print("2. Subtraction")

   print("3. Multiplication")

   print("4. Division")

   print("5. Remainder only")

   print("6. Quotient only")

   print("7. Exponentiation")

   print("8. Exit")

   print()

   c = int(input("Enter your choice: "))

   print()

   if c == 1:

       a = int(input("Enter a number: "))

       b = int(input("Enter a number: "))

       s = a + b

       print(s, "is the sum")

       print()

   elif c == 2:

       a = int(input("Enter the larger number: "))

       b = int(input("Enter the smaller number:"))

       d = a - b

       print(d, "is the difference")

       print()

   elif c == 3:

       a = int(input("Enter a number: "))

       b = int(input("Enter a number: "))

       p = a*b

       print(p, "is the product")

       print()

   elif c == 4:

       a = int(input("Enter the dividend: "))

       b = int(input("Enter the divisor"))

       q = a/b

       print(q, "is the quotient")

       print()

   elif c == 5:

       a = int(input("Enter the dividend: "))

       b = int(input("Enter the divisor: "))

       r = a%b

       print(r, "is the remainder")

       print()

   elif c == 6:

       a = int(input("Enter the dividend: "))

       b = int(input("Enter the divisor: "))

       q = a//b

       print(q, "is the quotient")

       print()

   elif c == 7:

       a = int(input("Enter a number: "))

       b = int(input("Enter the exponent: "))

       e = a**b

       print(e, "is the result")

   elif c == 8:

       break


Equestriadash: Thanks for the Brainliest!
Answered by sparklequeen62
2

# 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")

Output

Select operation.

1.Add

2.Subtract

3.Multiply

4.Divide

Enter choice(1/2/3/4): 3

Enter first number: 15

Enter second number: 14

15.0 * 14.0 = 210.0

Similar questions