how to make a calculator using python

#Store number variables for the two numbers

num1 = input('Enter first number: ')
num2 = input('Enter second number: ')

#the sum of the two numbers variable
sum = float(num1) + float(num2)
sum2 = float(num1) - float(num2)
sum3 = float(num1) * float(num2)
sum4 = float(num1) / float(num2)

#what operator to use
choice = input('Enter an operator, + = addition, - = subtraction, * = multiplication and / = division: ')
#different sums based on the operators
if choice == '+':
  print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

  if choice == '-':
    print('The sum of {0} and {1} is {2}'.format(num1, num2, sum2))

if choice == '*':
    print('The sum of {0} and {1} is {2}'.format(num1, num2, sum3))

if choice == '/':
    print('The sum of {0} and {1} is {2}'.format(num1, num2, sum4))
 

4.22
9
Phoenix Logan 186120 points

                                    #no gui

def  add(a,b):
    result=a+b
    print(result)

def sub(a,b):
    resulf=a-b
    print(resulf)

def mul(a,b):
    resulf=a*b
    print(resulf)

def div(a,b):
    resulf=a/b
    print(resulf)

a=int(input("enter th first number: "))
b=int(input("enter th second number: "))
op=input("enter the sign: ")

if op=="+":
    add(a,b)

elif op=="-":
    sub(a,b)    

elif op=="*":
    mul(a,b)  

elif op=="/":
    div(a,b)    

else:
    print("invalid")

4.22 (9 Votes)
0
3.83
6
Phoenix Logan 186120 points

                                    #You can change Text at Inputs

num1 = float(input("Enter Firt Number:"))
num2 = float(input("Enter Second Number"))

result= 0
op = str(input("Enter an op(operator)"))
#Gets Input Type--------
try:
  #U can make this in while loop ;-)
  if op=="+":
    result = num1 + num2
  else if op=="-":
    result = num1 - num2
  else if op=="*":
    result = num1 * num2
  else if op=="/":
    result = num1 / num2
  else:
      print("Invalid Input")
  print("The result is " + result)
except ZeroDivisionError:
  print("U cant do that")

3.83 (6 Votes)
0
3.5
6
Awgiedawgie 440220 points

                                    def add(num1, num2):
    return num1 + num2

def subtract(num1, num2):
    return num1 - num2

def multiply(num1, num2):
    return num1 * num2

def divide(num1, num2):
    return num1 / num2

3.5 (6 Votes)
0
4.5
2
Krish 100200 points

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

4.5 (2 Votes)
0
3.9
10
Awgiedawgie 440220 points

                                    #My Personal Python calculator
print("My Personal Python calculator")
#inputs
num1 = int(input('Enter the first number:  '))
num2 = int(input('Enter the second number:  '))
#opration req
opr = input('Enter the type of operation you want to perform between your chosen two numbers:  ')
#calculation
if opr=='+':
    ans = num1 + num2
    # displaying the answer
    print(f'Your final answer is {ans}')
elif opr == '- ':
    ans = num1 - num2
    # displaying the answer
    print(f'Your final answer is {ans}')
elif opr=='*':
    ans = num1 * num2;
    # displaying the answer
    print(f'Your final answer is {ans}')
elif opr=='/':
    ans = num1 / num2
    # displaying the answer
    print(f'Your final answer is {ans}')
else:
    print('Invalid Entry!!!')

3.9 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to make simple calculator in python make the best calculator in python python simple calculator with functions python program to basic calculator online calculator using python writing a calculator on python building a calculator in python python calculator online 2. Python Program to Make a Simple Calculator calculus calculator in python python as a calculator code Python as a calculator. how to code a simple calculator in python how to make a calculator in python source code calculator define python make calculator with python creating a simple calculator in python what is phython calculator programing a calculator to python python calculator function how to make calculator by using python building calculator in python how to solve basic calculator python create calculator in python Construct a python program to make a simple calculator. python make calculator simple calculator using function in python write a program to create a simple calculator in python python calculator script creating a calculator in python code python calculator python how to make a calculator python program for calculator python code for a working calculator calculator made with python create a calculator in python pytho calculator basic calculator with python python calculator example run calculator python calculator script python make calculator python how to create python calculator python program to build calculator calculator in python python calculataor calculatrice python coding python calculator program on python basic calculator using python creating calculator in python how to make a calculator using python code for calculator in python how to do calculator in python implement a calculator in pythn calculator basic in python calculator on python python calculas how to make calculator python calculator that use python to program calculators that use python simple calculator python script how to make calculator with python do a calculator in python coding on a calculaotr in python calculator coding in python simple calculator in python using swithcer code for a calculator in python build simple calculator using python code to make a calculator in python python code for a calculator make calculator using python make calculatrice using python Write a Python Program to demonstrate basic Calculator functionality using the concept of functions in Python. How to make an Calculator in python write a calculator code in python python calculator ans build a calculator using python calculatror python simple calculator code in python how to make a caculator in python how to code a python calculator how to do a calculator in python python program to design a SIMPLE CALCULATOR(Using functions). simple calculator operations python script for calculator in python how to make a python calculator python program to make a simple calculator (using functions) python make a calculator python script for calculator calculator python program Write a python program to design a SIMPLE CALCULATOR(Using functions). how to write calculator program in python python program to simple calculator calculator with python make calculator in python using funtions make calculator in python code for making calculator in Python does python have calculator basic python calculator code in python for calculator make a calculator in python how to make python calculator calculator in python for beiners how to create calculator in python how to create a simple calculator in python simple python program for calculator calculator in python calculator python tutorial how to make a calculator in python for beginners simple calculator in python using functions best calculator using python how to make a simple calculator in python creating a calcualtor in python python program to make simple calculator calculator in python code python basic calculator building calculator python calculator code python calculator using function in python how to use python as a calculator how to make a calculator in python python making a calculator python function calculator python calculator python script calculator calculator in python3 taking an operation as input how to calculate python how to make your own calculator software code for calculator how to make a coucalator python use built in calculator python creating a calculator python python make a simple calculator best python calculators simple calculator using def return in python The programe should performe the operation selected python create calculator with module basic calculator code making a calculator in python using functions python build calculator string simple calculator project in python arithmetic calculator python Python program make calculator calculator python \ function to calculate python python calculator file line python calculator program basic calculator in python using functions calculator python script calc in python how to have a calculating input in python making a calculator in python how to make python calculator which calculates two or 3 values basic calculator which can perform 2 or 3 number calculations python pythin calc package calculate x python calculator code in python for calculator code in python calculater app in python calculator code python 3 python simple calculator expression python module calculator program python input() to calculator create a calculator from modules in python making a simple calculator python module how to make calculator in pythone xplained how to add a calculation function in python python simple calculator making a text based calculator in python how to give input into calc.exe using python coding a simple calculator in python computation code python create bsaic calculator python how to create a calculator in python calculator program how to build a calculator in python calcualator with python how to make an ode calculator python how to make a calculator inpy calculator in pythonb basic calculator in python python calculator sample code simple calculator docs python use in python calculation create a calculator using python make calculator pythob python calculator calculator program in python python code calculator calculator questions program in python calc function in python python arithmic calcilator python module calculator calculator python 3 do a calculator in pytho create calculator python how to create calculator app in python implement calculator simple calculator using python online python calculator simple calculator command in python simple calculator program in python calculator based project python class 12 make console calculator in python simple calculator with python python interpreter as calculator code Pyhton calculator python input calculator program calculator Write a Calculator in Python python program that creates estimator python estimator program python simple calculator program calculatord you can do with python python code for calculator Homework 5: Multiplication Calculator python def function python calculation calculator using python python calculator basic code how to make a silmple calculaytor in python calculator using functions in python simple calculator python how to make calculator in python python calculator code code for python calculator simple calculator in python calculator program python calculator phython ptython code of calculator calculator python code cool calculators we can create with python basic calculator python how to code a calculator in python python calc how to make a simple calculator using python calcaulator in python making calculator in python calculator pyhton project calculate in python and display in c calculate lcpd python how to add a calculation in python calculator algorithm python calculator python input calculator python operations examples for calculator project python console calculator calculator project in python calculator python packages needed to build calculator python python Calculator Display a menu with operation options input how to create a calulator in python python simple calculator whith only integer make a basic calculator in python python code for calculator downloading file how to code calculator in python without function how to code calculator in python calculator on pyhotn Basical calculator python python list calculator generate python function given input and output data online calculator calculator excersise in python complication pyhton calculator calculator python source code python calculator code copy and paste simple python calculator
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source