Answers for "Calculator in python"

2

calculator in python

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
Posted by: Guest on August-13-2020
1

calculator in python

# 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()
Posted by: Guest on November-22-2020
3

calculator in python

def mutiply (x):
    return 5*x
o = mutiply(10)
print(o)
Posted by: Guest on June-20-2020
0

Calculator in python

num1 = input("Enter a Number : ")
num2 = input("Enter a Number : ")
result = (num1 * num2)
print(result)
# And then print out the result
Posted by: Guest on August-21-2020
0

calculator in python

# Define variables for number inputs..
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

# Input for operators
op = input("Enter operator: ")

# Functions for operations


def add(num1, num2):
    print('Result: ', num1 + num2)


def subtract(num1, num2):
    print('Result: ', num1 - num2)


def multiply(num1, num2):
    print('Result: ', num1 * num2)


def division(num1, num2):
    print('Result: ', num1 / num2)


# Using the functions
if op == '+':
    add(num1=num1, num2=num2)
elif op == '-':
    subtract(num1=num1, num2=num2)
elif op == '*':
    multiply(num1=num1, num2=num2)
elif op == '/':
    division(num1=num1, num2=num2)
else:
    print('Invalid operator')
Posted by: Guest on April-07-2021
0

calculator in python

#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)
Posted by: Guest on October-04-2020

Python Answers by Framework

Browse Popular Code Answers by Language