basic calculator in python

Solutions on MaxInterview for basic calculator in python by the best coders in the world

showing results for - "basic calculator in python"
Emanuele
17 Apr 2017
1#Store number variables for the two numbers
2
3num1 = input('Enter first number: ')
4num2 = input('Enter second number: ')
5
6#the sum of the two numbers variable
7sum = float(num1) + float(num2)
8sum2 = float(num1) - float(num2)
9sum3 = float(num1) * float(num2)
10sum4 = float(num1) / float(num2)
11
12#what operator to use
13choice = input('Enter an operator, + = addition, - = subtraction, * = multiplication and / = division: ')
14#different sums based on the operators
15if choice == '+':
16  print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
17
18  if choice == '-':
19    print('The sum of {0} and {1} is {2}'.format(num1, num2, sum2))
20
21if choice == '*':
22    print('The sum of {0} and {1} is {2}'.format(num1, num2, sum3))
23
24if choice == '/':
25    print('The sum of {0} and {1} is {2}'.format(num1, num2, sum4))
26 
Fabian
11 Jul 2018
1from tkinter import *
2import random
3import time
4
5def btnClick(numbers):
6	global operator
7	operator = operator + str(numbers)
8	text_Input.set(operator)
9
10def bcd():
11	global operator
12	operator = ""
13	text_Input.set("")
14
15def bei():
16	global operator
17	sumup = str(eval(operator))
18	text_Input.set(sumup)
19	operator = sumup
20
21
22root = Tk()
23root.title("Calculator")
24root.resizable(False, False)
25
26operator = ""
27text_Input = StringVar()
28
29#AnsShow
30textDisplay = Entry(root, font = ('arial', 20, 'bold'), textvariable = text_Input, bd = 30, insertwidth = 4, bg = "red", justify = 'right')
31textDisplay.grid(columnspan = 4)
32
33#button
34btn7 = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "7", command = lambda:btnClick(7)).grid(row = 1, column = 0)
35
36btn8 = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "8", command = lambda:btnClick(8)).grid(row = 1, column = 1)
37
38btn9 = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "9", command = lambda:btnClick(9)).grid(row = 1, column = 2)
39
40Add = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "+", command = lambda:btnClick("+")).grid(row = 1, column = 3)
41
42#============================================================================================================================#
43btn4 = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "4", command = lambda:btnClick(4)).grid(row = 2, column = 0)
44
45btn5 = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "5", command = lambda:btnClick(5)).grid(row = 2, column = 1)
46
47btn6 = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "6", command = lambda:btnClick(6)).grid(row = 2, column = 2)
48
49Sub = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "-", command = lambda:btnClick("-")).grid(row = 2, column = 3)
50
51#===============================================================================================================================#
52btn1 = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "1", command = lambda:btnClick(1)).grid(row = 3, column = 0)
53
54btn2 = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "2", command = lambda:btnClick(2)).grid(row = 3, column = 1)
55
56btn3 = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "3", command = lambda:btnClick(3)).grid(row = 3, column = 2)
57
58Multiply = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "*", command = lambda:btnClick("*")).grid(row = 3, column = 3)
59
60#==================================================================================================================================#
61btn0 = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "0", command = lambda:btnClick(0)).grid(row = 4, column = 0)
62
63equal = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "=", command = bei).grid(row = 4, column = 1)
64
65divide = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "/", command = lambda:btnClick("/")).grid(row = 4, column = 2)
66
67clear = Button(root, padx = 16, bd = 8, fg = "black", bg = "red", font = ('arial', 20, 'bold'), text = "c", command = bcd).grid(row = 4, column = 3)
68
69root.mainloop()
Camilla
29 Jul 2019
1#My Personal Python calculator
2print("My Personal Python calculator")
3#inputs
4num1 = int(input('Enter the first number:  '))
5num2 = int(input('Enter the second number:  '))
6#opration req
7opr = input('Enter the type of operation you want to perform between your chosen two numbers:  ')
8#calculation
9if opr=='+':
10    ans = num1 + num2
11    # displaying the answer
12    print(f'Your final answer is {ans}')
13elif opr == '- ':
14    ans = num1 - num2
15    # displaying the answer
16    print(f'Your final answer is {ans}')
17elif opr=='*':
18    ans = num1 * num2;
19    # displaying the answer
20    print(f'Your final answer is {ans}')
21elif opr=='/':
22    ans = num1 / num2
23    # displaying the answer
24    print(f'Your final answer is {ans}')
25else:
26    print('Invalid Entry!!!')
Mattia
06 Nov 2020
1# This will be one of the most advanced results you will find.
2
3# We will be using classes and simple operators like +,-,*,/
4
5class Calculator:
6  def addition(a,b):
7    return a + b
8
9  def subtraction(a,b):
10    if a<b:
11      return b - a
12    else:
13      return a - b
14
15  def multiplication(a,b):
16    return a * b
17
18  def division(a,b):	
19    if a<b:
20      return b / a
21    else:
22      return a / b
23
24# You can do this in terminal.
25<C:/Users/username>python
26>>> from main import Calculator
27>>> result = Calculator.[addition|subtraction|multiplication|division](anyNumber, anyNumber)
28>>> print(result)
Maite
07 Sep 2019
1num1 = input("Enter a Number : ")
2num2 = input("Enter a Number : ")
3result = (num1 * num2)
4print(result)
5# And then print out the result
Mira
09 Oct 2019
1a=int(input("first number:"))
2b=int(input("second number:"))
3c=input("what you want +,-,*,/: please input sign:")
4d=("+")
5e=("-")
6f=("*")
7g=("/")
8if c==d:
9    print(f"your answer is: ({a+b})")
10elif c==e:
11    print(f"your answer is:({a-b})")
12elif c==f:
13    print(f"your answer is:({a*b})")
14elif c==g:
15    print(f"your answer is:({a/b})")
16print ("thank you")
17
queries leading to this page
build a calculator using pythonpython simple calculator whith only integerhow to make a calculator in pythonbasic calculator using pythoncalculater app in pythonpython code to make a calculatorpython calculas programhow to create a calculator program in pythonpython code calculator with stepshow to code calculator in python without functionpython how to make a calculatorcalculator on pythonpython input 28 29 to calculatorcalculatror pythondo a calculator in pythonsimple calculator in python using swithcerimplement a calculator in pythnhow to make calculator by using pythonpython basic calculatorhow to code a simple calculator in python using functionspython calculatorsimple basic calculator with pythoncalculator that runs pythonmake the best calculator in pythonhow to code a python calculatorhow to add a calculation in pythoncreating a calculator in pythonpython program to make a calculatorcoding a simple calculator in pythonpython calculator display a menu with operation options inputhow to make calculator in pythonbuilding calculator pythoncalculator pyhtonvery basic python calculatorpython module calculator programsimple calculator pythonpython program to make simple calculatorbuilding a calculator in pythoncalculator code in python for python calculatiorcalculator using pythonbest python calculatorimplement calculatorhow to make a simple calcualator in pythoncode for making calculator in pythoncan you code a calculator in pythonuse built in calculator pythoncreate a calculator where user have a menu to perform addition 2f subtraction 2f multiplication 2f division 2f display tables using loops in python python program to create a calculatorcalculator program in pythondoes python have calculatorcreate a calculator in pythonhow to do calculator in pythonsimple calculator code in pythonhow to run python calculator codetaking an operation as input how to calculate pythonpython calculator programpython calculate 28 29calculator code in pythonhomework 5 3a multiplication calculator pythoncalculator python code glebber how to make a python calculatorcode for calculatormaking a simple calculator in pythonpython script calculatormake console calculator in pythoncalculator in python functionwhat is phython calculatormake a calculator with defining in pythonstrcutured package for calculator using pythonhow to create a simple calculator in pythonhow to make a calculator inpycalculator making in pythonhow to use python as a calculatorcalculation using functions python the programe should performe the operation selectedsimple calculator with pythonhow to make a addition calculator in pythondo a calculator in pythobasic py calculatorpython make a calculatorcalculator program in python using functionssimple calculator using pythoncalculator price in python using functionshow to make a simple python calculatorpython projects using calculationspython input calculatorsimple calculator project in pythoncalculator syntax for pythoncomputation code pythonhow to create a web based calculator with pythonfunction to calculate python calculator in pythonmake calculator pythobcalculaor with pythoncalculator python codecreate calculator in pythonhow to make a coucalator pythoncode for calculator in pythonwrite a calculator code in pythonhow to make a calculator in python simple beginnerpython calculator examplepython program to make calculatorpython calcmaking calculator in pythonhow to solve basic calculator pythonmaking a calculator in pythonhow to use python on your calculatorcalculator algorithm pythoncode to make a calculator in pythonprograming a calculator to pythonhow to make calculator in pythone xplainedmaking a text based calculator in pythonoperations examples for calculator projectcalculator basic in pythoncalculator codegenerate python function given input and output data online calculatorpython as a calculator codecalculate x pythonmake a caleculatoer in pythonbest calculator in pythonpython calcualtorpython simple calculator program2 09python program to make a simple calculatorhow to code a calculator in pythonpython program to build calculatorvlsm calculator pythonhow to write calculator program in pythonwhat do you need to create a python calculatorhow to give input into calc exe using pythonhow to make python calculatorcalculate function do in pythonpython list calculatormake calculator pythonpython calculator file linecalculator python 5ccan you make a calculator using pythonpytho calculatorpython calorie calculatorbuild calculator with pythonpython program to simple calculatorhow to make a calculator using pythoncalculator using functions in pythonbasic calculator which can perform 2 or 3 number calculations pythoncalculator pythonsimple calculator using function in pythoncreate a calculator from modules in pythonbasic calculator pythoncode in python for calculatorhow to code calculator in pythonpython calculatorpython calculator add simplecode for making a calculator in pythonsimple calculator docs pythonpython calculashow to build a calculator in pythonmake a simple calculator in pythonhow to add a calculation function in pythonpython module calculatorpython calculator code copy and pastepython calculataorwrite a program to create a simple calculator in python python arithmic calcilatorhow to make a simple calculator using pythonbasic calculator with pythonwrite a python program to design a simple calculator 28using functions 29 coding on a calculaotr in pythonmake calculator in python using funtionspython estimator programpython as a calculator code calculator pythonhow to create a calcualtor in python3basical calculator pythoncalculator codes in pythonpython calculator functionhow to make a calculator pythonsimple calculator python scripthow to make a subtraction calculator in pythoncode calculatrice pythonworking calculator pythonhow to make calculator pythonwrite a python program to demonstrate basic calculator functionality using the concept of functions in python simple calculator command in pythonmaking a calculator in python using functionscool calculators we can create with pythonpython calculator example with chekccreating calculator in pythonpython calculator code displaypy calculatorpython simple calculator expressionhow to make a basic calculator in pythonpython as a calculatorbesic calculator in phytoncreate a function calculator in pythonhow to make a caculator in pythonhow to code a simple calculator in pythonpython calculator codeswrite a python program for calculatormake a calculator in pythononline python calculatorhow to make python calculator which calculates two or 3 valuescalculator program pythoncreating a simple calculator in python python interpreter as calculator codehow to make simple calculator in pythonpython program calculatorcalculate lcpd pythoncalculator pythonbuilding calculator in pythonuse in python calculationwriting a calculator in pythonhow to make a simple calculator using functions in pythonhow to make basic calculator in pythonpython script for calculatorptython code of calculatorcalculator coding pythonhow to create a calulator in pythoncalculator questions program in pythonbuild a calculator in pythonsimple calculator python codeimplement basic calculator pythonpython as calculatorcalculator in python projectcalculators that use pythoncalculator in python codewhat does calculate function do in pythonpyhton calculatorhow to calculate using pythonpython build calculator stringdef function python calculationcalculator project in pythonhow to make calculator with pythoncode for a calculator in pythoncalculate in python and display in ccalcualator with pythonrun calculator pythoncalculator in pyhtoncalculator pyhton projectpython code for a working calculatorpython calculator program on pythoncode python calculatorimport calculator in pythonpython calculator sample codepython simple calculator with functionscreate calculator pythonhow make a calculator in pythoncalculator python programmake calculator with pythoncalculator in python for beinerscreate a calculator using pythoncalculator python projectcreate a calculator function pythonpython create function that calculatescalculator on pyhotnpython code for a calculatorpython code for calculatorpython program to basic calculatorconstruct a python program to make a simple calculator complication pyhton calculatorarithmetic calculator pythoncalculator script pythoncreate calculator using pythoncalculatord you can do with pythoncalculator python source codeinput calculator pythonsimple python calculatorwrite a program that performs the tasks of a simple calculator the program should first take an integer as input and then based on that integer perform the task as given below create your own calculator function pythonbuild simple calculator using pythoncalcaulator in pythonhow to make a calculator in puthoncalc function in pythonbasic calculator in python using functionspython code for calculator downloading filepython make calculatorpython simple calculatorcalculus calculator in pythonsimple python program for calculatoronline calculator using pythonbest calculator using pythonpython program to make a simple calculator 28using functions 29calculator code pythonhow to create calculator app in pythoncalculator in pythpython calculator scriptpythin calc packagepython calculator anspython make a simple calculatorcalculatrice python codinghow to write a calculator program in pythoncode for calculator app in pythonhow to make a calculator in python for beginnersprogram calculatorcalculator excersise in pythoncalculator python 3python program that creates estimatorsimple calculator in python calculator phythoncalculator python scriptpython code calculatorsimple calculator in python using functionspython calaculatorpythion calculatorcalculator python tutorialbasic python calculatorhow to make your own calculator softwarecalculadora pythonhow to create calculator in pythoncalculator that use python to programpython calculator codeingsimple calculator program in pythonpython program for simple calculatormake a basic calculator in python basic calculator in pythongenerating a calculator with pythonpython how to code a calculatorsimple caculation pythonpython caculatorcalculator in pythoncode for python calculatorsimple calculator operations pythonhow to build a calculator in pythonbasic calculator pytcalculator made with pythonpython program to design a simple calculator 28using functions 29 how to create python calculatorcalc in pythonhow to make calculator pytonmake a python calculator for ligningercalculator using function in pythoncalculator in python3how to make a calcualtor pythoncalculator coding in pythonhow to make 22function calculator 22 in pythonpython code for calcculatormethods in pythond clculationpython calculator codecalculatrice with pythonbasic calculator codepython console calculatormaking a simple calculator python modulecalculator source code in pythonhow to make a calculator python 2calculator with pythonpython calculator basic codecalculator program in python using functionmake a simple calculator using python mathematical operations best python calculatorshow to create a calculator in pythoncalculator in pythonbhow to make a silmple calculaytor in pythonwrite a program to perform calculator operations in pythonscript for calculator in pythonhow to make an calculator in pythonwith what module can i create calculator in pythoncalculator code python 3how to make a simple calculator in pythonhow to do a calculator in pythonhow to build a calculator in pytonpackages needed to build calculator pythonwrite a calculator in pythonpython calculaor filecalculat pythonhow to make a boolean function in pythonpython calculator onlinewriting a calculator on pythonpython program for calculatorpython function calculatormake calculator in pythonpython making a calculatorhow to make function calculator in pythonhow to have a calculating input in pythonmake calculator using pythonmake calculatrice using python how to make a calculator in pythonbasic calculator in python