0
Q:

calculator in python

num_one = input("Enter 1st number: ")
num_one = int(num_one)

op = input("Enter operator: ")

num_two = input("Enter 2nd number: ")
num_two = int(num_two)

if op == "+":
    print(num_one + num_two)
elif op == "-":
    print(num_one - num_two)
elif op == "*":
    print(num_one * num_two)
elif op == "/":
    print(num_one / num_two)
4
# try to run this in repl.it to get the better experience

from replit import clear
# from art import logo

def add(n1, n2):
  return n1 + n2

def subtract(n1, n2):
  return n1 - n2

def multiply(n1, n2):
  return n1 * n2

def divide(n1, n2):
  return n1 / n2

operations = {
  "+": add,
  "-": subtract,
  "*": multiply,
  "/": divide
}

def calculator():
  print(logo)

  num1 = float(input("What's the first number?: "))
  for symbol in operations:
    print(symbol)
  should_continue = True
 
  while should_continue:
    operation_symbol = input("Pick an operation: ")
    num2 = float(input("What's the next number?: "))
    calculation_function = operations[operation_symbol]
    answer = calculation_function(num1, num2)
    print(f"{num1} {operation_symbol} {num2} = {answer}")

    if input(f"Type 'y' to continue calculating with {answer}, or type 'n' to start a new calculation: ") == 'y':
      num1 = answer
    else:
      should_continue = False
      clear()
      calculator()

calculator()
2
def mutiply (x):
    return 5*x
o = mutiply(10)
print(o)
3
# simple calculator
try:
  # prompt user
    num1 = float(input("Please Enter The first number: "))
    operator = input("Please choose the operator (+) for addition, (-) for subtraction, (*) for multiplication"
                     "(/) for division , (%) for remainder: ")
    num2 = float(input("Please Enter The second number: "))
    
    if operator == '+':
        result = num1 + num2
        print("The result is: ", result)
    elif operator == '-':
        result = num1 - num2
        print("The result is: ", result)
    elif operator == '*':
        result = num1 * num2
        print("The result is: ", result)
    elif operator == '/':
        try:
            if True:
                result = num1 / num2
                print(result)
        except ZeroDivisionError as err:
            print(err, " oops! zero division occur ")
    elif operator == '%':
        if operator == '%':
            result = num1 % num2
            print("The result is: ", result)
    else:
        raise TypeError


except ValueError:
    print("wrong value, suggest integer or decimal")
finally:
    print("All Done")
0
# Python program for simple calculator 
  
# Function to add two numbers  
def add(num1, num2): 
    return num1 + num2 
  
# Function to subtract two numbers  
def subtract(num1, num2): 
    return num1 - num2 
  
# Function to multiply two numbers 
def multiply(num1, num2): 
    return num1 * num2 
  
# Function to divide two numbers 
def divide(num1, num2): 
    return num1 / num2 
  
print("Please select operation -\n" \ 
        "1. Add\n" \ 
        "2. Subtract\n" \ 
        "3. Multiply\n" \ 
        "4. Divide\n") 
  
  
# Take input from the user  
select = input("Select operations form 1, 2, 3, 4 :") 
  
number_1 = int(input("Enter first number: ")) 
number_2 = int(input("Enter second number: ")) 
  
if select == '1': 
    print(number_1, "+", number_2, "=", 
                    add(number_1, number_2)) 
  
elif select == '2': 
    print(number_1, "-", number_2, "=", 
                    subtract(number_1, number_2)) 
  
elif select == '3': 
    print(number_1, "*", number_2, "=", 
                    multiply(number_1, number_2)) 
  
elif select == '4': 
    print(number_1, "/", number_2, "=", 
                    divide(number_1, number_2)) 
else: 
    print("Invalid input") 
5
# define the function
def calculate():
    print('Please choose your operator adding(+) subtracting(-) multiplying(*) didviding(/) for power(**) for module(%)')

    number_1 = int(input("Enter your first digit: "))
    operation = input("Enter your operator: ")
    number_2 = int(input("Enter your first digit: "))


# adding
    if operation == '+':
        print('{} + {} = '.format(number_1, number_2))
        print(number_1 + number_2)
        print("You were adding.\n")
        print("How do I know that I'm a smart progammer ;)\n")

# subtracting
    elif operation == '-':
        print('{} - {} = '.format(number_1, number_2))
        print(number_1 - number_2)
        print("You were subtracting.\n")
        print("How do I know that I'm a smart progammer ;)\n")

# mulitplaying
    elif operation == '*':
        print('{} * {} = '.format(number_1, number_2))
        print(number_1 * number_2)
        print("You were mulitplaying.")
        print("How do I know that I'm a smart progammer ;)\n")

# dividing
    elif operation == '/':
        print('{} / {} = '.format(number_1, number_2))
        print(number_1 / number_2)
        print("You were dividing.\n")
        print("How do I know that I'm a smart progammer ;)\n")

# for power
    elif operation == '**':
        print('{} ** {} = '.format(number_1, number_2))
        print(number_1 ** number_2)
        print("You were using for power.\n")
        print("How do I know that I'm a smart progammer ;)\n")

# module
    elif operation == '%':
        print('{} % {} = '.format(number_1, number_2))
        print(number_1 % number_2)
        print("You were using module.\n")
        print("How do I know that I'm a smart progammer ;)\n")

    # if they get a error
    else:
        print("Your number you have typed is invalid, please restart your program!")
    # add again() here as a function outside the calculate()
    again()


def again():
    cal_again = input("Do you want to calculate again? Y = yes or N = no: ")

    # Taking user input
    if cal_again.upper() == 'Y':
        calculate()
    elif cal_again.upper() == 'N':
        print('Leave kid ;-;')
    else:
        again()


def welcome():
    print("Welcome to my calculator made by Pepa pig lol made in python :D")


# use calculate() for the function
welcome()
calculate()
0
print("Choose operator (+,-,*,/):")
mode = input()
print("Choose first int:")
x = int(input())
print("Choose second int:")
y = int(input())

print("Your result:")
if mode == "+":
    print(x+y)
elif mode == "-":
    print(x-y)
elif mode == "*":
    print(x*y)
elif mode == "/":
    print(x/y)
0
num1 = input("Enter a Number : ")
num2 = input("Enter a Number : ")
result = (num1 * num2)
print(result)
# And then print out the result
0
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
0
#Calculator in python
#No modules required
qus = input('')
if(qus=='ADDITON'):
  no1 = int(input())
  no2 = int(input())
  print(no1+no2)
  
if(qus=='MULTIPLICATION'):
  no1 = int(input())
  no2 = int(input())
  print(no1*no2)

if(qus=='DIVISION'):
  no1 = int(input())
  no2 = int(input())
  print(no1/no2)
  
if(qus=='SUBTRACTION'):
  no1 = int(input())
  no2 = int(input())
  print(no1-no2)
0

New to Communities?

Join the community