how to create calculator in python

Solutions on MaxInterview for how to create calculator in python by the best coders in the world

showing results for - "how to create calculator in python"
Malone
12 Aug 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 
Emanuele
24 Sep 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()
Mats
09 Mar 2018
1#Calculator
2
3import time
4
5def add():
6  n1 = input('Enter a number: ')
7  n2 = input('Enter another number: ')
8  time.sleep(1)
9  print(int(n1)+int(n2))
10  
11def multiply():
12  n1 = input('Enter a number: ')
13  n2 = input('Enter another number: ')
14  time.sleep(1)
15  print(int(n1)*int(n2))
16    
17def divide():
18  n1 = input('Enter a number: ')
19  n2 = input('Enter another number: ')
20  time.sleep(1)
21  print(int(n1)int(n2))
22  
23def subtract():
24  n1 = input('Enter a number: ')
25  n2 = input('Enter another number: ')
26  time.sleep(1)
27  print(int(n1)-int(n2))
28  
29run = True
30while run:
31  ans = input('Select an opreation: ')
32  if(ans=='Addition'):
33    add()
34    
35  if(ans=='Divide'):
36    divide()
37    
38  if(ans=='Multiply'):
39    multiply()
40    
41  if(ans=='Subtract'):
42    subtract()
43  
44  
45  
Alejandra
14 May 2020
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!!!')
Federica
05 Jan 2019
1num_one = int(input("Enter 1st number: "))
2
3op = input("Enter operator: ")
4
5num_two = int(input("Enter 2nd number: "))
6
7if op == "+":
8    print(num_one + num_two)
9elif op == "-":
10    print(num_one - num_two)
11elif op == "*" or op == "x":
12    print(num_one * num_two)
13elif op == "/":
14    print(num_one / num_two)
15
Mathis
17 Jul 2019
1x = input("first number")
2y = input("second number")
3z = input("do you want to multiply, minus, divide or add? (x,-,/,+)")
4
5y = int(y)
6x = int(x)
7
8if z == "+":
9    print (x + y)
10
11if z == "/":
12    print (x / y)
13
14if z == "x":
15    print (x * y)
16
17if z == "-":
18    print (x - y)
19
20else:
21    print("use x,-,/ or + next time!")
queries leading to this page
python print calcwriting a calculator on pythoncalculator made with pythoncalculator codepython input 28 29 to calculatorbasic calculator pytcreate a calculator in pythonhow to write calculator program in pythonpython program make calculatorwrite a calculator in pythonhow to make your own calculator softwarepython program to simple calculatorhow to make a simple calculator using pythoncalculator pythonpython code for calculator downloading filemake calculator in pythonhow to make a calculator in pythonwrite a calculator code in pythoncan you make a calculator with pythoncalcuator codepython on calculatorcalculatore pythonmake calculator pythonpython make calculatorpython program to build calculator the programe should performe the operation selecteddevelop a menu driven python program to design a simple calculator for arthematic and relational operatorpython calculascreate calculator using 4 functionspackages needed to build calculator pythonhow to make a calculator in python 8 digitspython calculatorwrite a python program to demonstrate basic calculator functionality using the concept of functions in python how to create python calculator calculator onlinecalculator using functions in pythonpython create function that calculatespython program to basic calculatorhow to write a calculator program in pythonbuild a calculator in python forpython make a simple calculatorcalculator syntax for pythonpython as a calculator make console calculator in pythoncalculator python codemake a simple calculator using python mathematical operations how to make basic calculator in pythoncalculator python 5cmake calculator using pythonhow to create a calculator with pythononline calculator using pythonpython code for a working calculatorbasic calculator using pythoncalculate x pythononline python calculatorcalculator code python 3calculator javascript codepython arithmic calcilatorhow to make a calculator pythonoperations examples for calculator projectpython calculator onlinebasic calculator in pythoncalculator ui htmlpython calculator codeshow to make a calculator in html with javascriptcalculator using function in pythonhow to make a addition calculator in pythonpython create module calculatorcalculat pythonmaking a calculator in python using functionscalculator script pythonbasic calculator which can perform 2 or 3 number calculations pythonmake the best calculator in pythoncalculatrice python codingdo a calculator in pythocalculator that runs pythonmaking a simple calculator in pythonmake a basic calculator in python calculator coding pythonhow to make a calculator in python source codecalculator html and javascriptcalculator in jshow to make simple calculator in pythonworking calculator pythonpython calcualtorhow to make a calculator javascriptwrite a python program for calculatormake a calculator using javascriptbuild calculator with pythoncalculator python projectjs calculator coderun calculator pythonpython how to make a calculatorbasical calculator pythonsimple calculator in python using swithcercalculator on pyhotnpython program to design a simple calculator 28using functions 29 make calculator 25 calculatorphython calculatorpython calculas programcalc function in pythonhow to build a calculator with javascriptcode for calculatorpython program to create a calculatorhow to make a calculator in puthonhow to make calculator in javascriptcalculator in python codehow to create a simple calculator in pythoncalculator on pythonpython module calculator programcode for a calculatorsimple calculator in python using functionspython program to make a simple calculator 28using functions 29build a calculator in pythonwrite a program to create a simple calculator in python calculator using pythonpython calculator code downloadpython calculator projecthow to make a claculator in pythonpython script for calculatormaking a calculator with javascriptcode ofr a calculatorcalculatore codepython make a calculatorcreate your own calculator function pythoncalculatorluse in python calculationpython calculator examplehow to make calculator pytoncreate a calculator using pythonpython program to make a calculatorsimple calculator operations pythonpython program calculatorpython simple calculatorcode in python for calculatorjavascript calculatorcalculator in pythpython as a calculatorhow to use python on your calculatorhow to make a calculator using pythoncalculator program in pythonpython program for calculatorcode calculator pythonhow to make python calculatorpython calculatorpython simple calculator expressionhtml calculator examplejavascript calculator without input fieldptython code of calculatorcalc in pythonhow to build a calculator in pythoncreate and test an html document that has a basic calculator how to create calcultor in pythonmaking calculator in javascript 25 calculator for pythoncalculation method pythoncreate a calculator function pythoncool calculators we can create with pythoncalculator python scriptcalcualator with pythoncode for making calculator in pythonhow to create calculator app in pythoncalculator in python for beiners calutator htmlhow to create a calculator in pythonpythion calculatorhow to make an calculator in pythonpython calculator code pdfpython basic calculation between two numbershow to add a calculation in pythoncalculator python 3 3d calculatorcalculator code in python for how to give input into calc exe using pythonpython simple calculator programcaluclator model in java scriptimplement basic calculator pythonpython calculator program on pythoncalculator app in python python program to make simple calculatorcode for a calculator in pythoncalculator 5csimple calculator project in pythonsimple calculator with pythoncalculator basic in pythonfunction to calculate python simple calculator command in pythoncode for simple calculator in pythonhow to create a calculator in python3build simple calculator using pythoncalculator code in pythonsimple calculator docs pythonhow to make python calculator which calculates two or 3 valuespyhton calculatorcalculators that use pythoncalculator module pythonpython script calculatorpython code calculatorcalculatror pythoncalculator that use python to programpython calculator display a menu with operation options inputhow to make calculator by using pythonmake a simple calculator in pythonpython code to make a calculatorcreating a simple calculator in python python code for a calculatorhow to build a calculator in pythonscript for calculator with html and javascriptsimple calculator using pythoncalculator 25calculater app in pythoncalculator htmlmaking a simple calculator python modulehow to code a calculator in pythonsimple calculator program in pythoncalculator js htmlpython calculator modulearithmetic calculator pythoncalculate in python and display in ccalculator with pythonsimple python program for calculatorcalculator questions program in pythonhow to have a calculating input in pythonwrite a program to perform calculator operations in pythonscript for calculator in pythonpython code for calculatorcalculator code using pythonpython calorie calculatorcalculator using javascriptcalculator program in python using functionconstruct a python program to make a simple calculator simple calculator pythonbasic calculation app in htmljavascript calculator codegenerating a calculator with pythonwant to code a calculator with different values python code to creae a calculatorhow to make a calcualtor pythonhow to solve basic calculator pythonmake calculator with pythonwriting a calculator in pythondoes python have calculatorcreate multiple calculator using javascriptcalculator in pyhtonhow to make a calculator in pythonwhat is phython calculatorcreate a calculator from modules in pythoncalculator in pythonbcalculator python programwhat is the code for a calculatorcalculator pythoncode calculatorpython build calculator stringpython ccalculetorpython calculataorhow to make a simple python calculatormake a calculator on python vs codehow to make a simple calculator using functions in pythonpythin calc packagedef function python calculationprograming a calculator to pythonhow to make a simple calculator in pythonpython estimator programcalculator codes in pythonbasic calculator with pythoncalculatord you can do with pythonpython calaculatora calculator code with pythonpython as a calculator codecoding on a calculaotr in pythonhow to make a python calculatorcalculator program in python using functionspython calculator procalculator program pythoncalculator code pythoncalculator project in pythonpython calculatiorpython calculator ansmake calculator pythobpython calcsimple python calculatorcreate a function calculator in pythonhow to make calculator in pythonkundi calculatorhomework 5 3a multiplication calculator pythonhow to open and operate calculator with pythoncalculator excersise in pythonsimple caculation pythoncreating a calculator in pythonsimple calculator python codeexamples of calculations in pythonhow to create a calulator in pythonsimple calculator using function in pythoncoding a simple calculator in pythonmaking a calculator in pythonbasic calculator codepython calculator scripthtml5 make calculatorpython calculator file linemake a calculator jspython program to make calculatorgenerate python function given input and output data online calculatorpython calculator basic codehow to make calculator with pythonbuilding calculator javascripthow to make an ode calculator pythoncalculator making in pythonpython simple calculator whith only integercan you make a calculator using pythonbuilding calculator pythoncalculator python source codepyton calculator codesimple basic calculator with pythonpython interpreter as calculator codehow to make calculator pythonpython calculator sample codehow to make a silmple calculaytor in pythonhow to make a calculator in python for beginnershow to make function calculator in pythoncalculator coding in pythonscientific calculator algorithm in javascriptmaking a python calculatorcode for python calculatormake calculator in python using funtionscreate calculator pythonjs calculatorcalculator 27how to make a calculatorcalculator onlinepython basic calculatorpython calculator programbasic calculator in python using functions calculator in pythoncode calculatrice pythoncalculator codingcalculator in htmlcomputation code pythondo a calculator in pythoncode to make a calculatortaking an operation as input how to calculate pythonhow to use python as a calculatorhow to build a calculator in jscal calculatorhow to add a calculation function in pythonpython calculator functionpython simple calculator with functionscalculator how to make a coucalator pythonhow to code calculator in pythonwrite a python program to design a simple calculator 28using functions 29 make a calculator in pythoncalculator pyhton projectcalculator logic in javascriptcreating calculator in pythondevelop a menu driven python program to design a simple calculator python as calculatorcode to make a calculator in pythononline calculator codehow to make a calculator inpypython making a calculatorsimple calculator python scripthow to make a calculator with javascriptbuilding a calculator in pythonmake calculatrice using python calculator algorithm pythoncalculator 5dmaking calculator in python2 09python program to make a simple calculatorhow to build a calculator in pytoncalculator app using javascriptcalculator in html and javascriptuse built in calculator pythoncalculatrice with pythoninput calculator pythonimplement calculatorcalculator price in python using functionscan you code a calculator in pythonpython input calculatorcalculator module in pythoncalculatorcalcaulator in pythonhow to make calculator in pythone xplainedbest calculator using pythoncalculater codecomplication pyhton calculatorbest python calculatorscalculus calculator in pythoncreate bsaic calculator pythonpython calcultorhow to run python calculator codecode python calculatorsimple calculator code in pythonhtml calculatorsjavascript notes to make a calculatorbuild a calculator using pythoncalculator html jscalculator with javascript htmlhow make a calculator in pythoncalculate lcpd pythonbest calculator in pythonbasic python calculatorhtml calculatorcalculator in pythonpython program for simple calculatorcalculator in python3how to write calculations in pythonhow to make a calculator with python calculator phythonprogramming a calculatorcode for calculator in pythonpytho calculatorcalculator js codehtml calculatorhow to do a calculator in pythonhow to code calculator in python without functioncode to make calculator in pythonhow to code a python calculatorcalculator jspython program that creates estimatorpython calculator codepython module calculatorpython list calculatorhow to make a calculator jshow to code a simple calculator in pythoncalculating efence using pythonhow to create a calculator program in pythonhow to make a caculator in pythonhow to create calculator in pythonsimple logic for calculatorpython console calculatorimplement a calculator in pythncalculator app pythonbuilding calculator in pythoncode caculatorwrite menu based program in python to create a four way calculatorhow to make 22function calculator 22 in pythonpython function calculatorbasic calculator program in pythonhow to make a basic calculator in pythoncreate calculator in pythonhow to make a calculator in python sim0oerealtivebearing python calculatorsimple calculator in pythonis calculate a function in pythoncalculator using javascript codewhat do you need to create a python calculatorpython calculator code copy and pasteprogram calculatorbasic calculator pythonhow to do calculator in pythonmaking a text based calculator in pythonhow to code a calculatorm 2cake a calculator in jshow to create calculator in python