how to create a calculator in python

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

showing results for - "how to create a calculator in python"
Luna
11 Aug 2019
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()
Till
25 May 2018
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 
Adame
27 Jan 2018
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!!!')
Juan Diego
11 Jun 2017
1Select operation.
21.Add
32.Subtract
43.Multiply
54.Divide
6Enter choice(1/2/3/4): 3
7Enter first number: 15
8Enter second number: 14
915.0 * 14.0 = 210.0
10
Jessica
20 Jan 2018
1def calculate():
2    operation = input('''
3Please type in the math operation you would like to complete:
4+ for addition
5- for subtraction
6* for multiplication
7/ for division
8''')
9
10    number_1 = int(input('Please enter the first number: '))
11    number_2 = int(input('Please enter the second number: '))
12
13    if operation == '+':
14        print('{} + {} = '.format(number_1, number_2))
15        print(number_1 + number_2)
16
17    elif operation == '-':
18        print('{} - {} = '.format(number_1, number_2))
19        print(number_1 - number_2)
20
21    elif operation == '*':
22        print('{} * {} = '.format(number_1, number_2))
23        print(number_1 * number_2)
24
25    elif operation == '/':
26        print('{} / {} = '.format(number_1, number_2))
27        print(number_1 / number_2)
28
29    else:
30        print('You have not typed a valid operator, please run the program again.')
31
32    # Add again() function to calculate() function
33    again()
34
35def again():
36    calc_again = input('''
37Do you want to calculate again?
38Please type Y for YES or N for NO.
39''')
40
41    if calc_again.upper() == 'Y':
42        calculate()
43    elif calc_again.upper() == 'N':
44        print('See you later.')
45    else:
46        again()
47
48calculate()
Alessandro
20 Feb 2017
15+5=
2
3
4
5
6
7
8
9
10
11
12
13
queries leading to this page
python code for a working calculatordoes python have calculatorcalculator evolution idleuse built in calculator pythoncreate a calculator from modules in pythonhow to make simple calculator in pythonpython list calculatorsimple calculator in pythonmake calculator using pythonimplement a calculator in pythnhow to build a calculator in pytonhow to create a calulator in pythoncan you code a calculator in pythonpython make a calculatorcalculator idlepython calculator codepython programs on calculatorcalculator coding pythonpython basic calculatorpython calucaltor codearithmetic calculator pythonbasic calculator in pythoncalculator algorithm pythonmake the best calculator in pythonmaking a calculator in python using functionshow to make calculator in pythonsimple calculator code in pythonbuild calculator with pythoncalculator program in python using functionstaking an operation as input how to calculate pythonbest python calculatorspython calculator display a menu with operation options inputcreate calculator in pythonpython input calculatorbuild a calculator using pythonpackages needed to build calculator pythonhow to make a calculator pythonmaking a simple calculator in pythonpython simple calculator whith only integerpython program for calculatorpython calculator project code pdfprograming a calculator to pythonpython code for a calculatorcalclator python codrpython 3 course calculatorhow to create python calculatorcalculator excersise in pythonwrite a program to create a simple calculator in python python calculator program using main functioncalculator questions program in pythonhomework 5 3a multiplication calculator pythonhow to use python as a calculatorfunction to calculate python python create function that calculatespython script for a calculatorhow to make a calculator app in pythoncool calculators we can create with pythoncalcaulator in pythonpython calculatiorcode in python for calculatorwrite a calculator code in pythonmake a calculator in pythonbsic claculator in python imagescalculator syntax for pythonpython program to design a simple calculator 28using functions 29 arithmetic calculator in pythonhow to make a calcultor in python using funtionhow to write a calculator program in pythonsimple caculation pythonhow to make a muliple number calculater in pythonpython calculator code copy and pastesimple calculator in python using functionsscript for calculator in pythonpython calculas programcalculatror pythonpyhton calculatorhow to make calculator pythonmaking a calculator in pythonbuild a calculator with pythondef calculator pythonuse in python calculationcalculator made with pythonpython tutorial how to build a calculatorhow to make a simple python calculatorcalculatrice python codingpython program to create a calculatorhow to code a python calculatorhow to make a calculator in pythoncode for python calculatorcalculate x pythonpython module calculatorhow to make calculator in pythone xplainedhow to do calculator in pythonpython program for simple calculatorpython calculator program on pythonhow make a calculator in pythoncalculatord you can do with pythoncreating a calculator in pythonoperations examples for calculator projectpython as a calculator how to create calculator app in pythonhow to build a calulator in pythonbuild simple calculator using pythoncreating a simple calculator in python implement basic calculator pythonsimple calculator python codecalculator code python 3make a custom form calculator pythonconstruct a python program to make a simple calculator how to add a calculation function in pythonpython calculate operation by secondcode for making a calculator in pythoncalculator app in pythonbuilding calculator in pythonpython calcualtorsimple calculator command in pythonpython calculataorsimple calculator with pythonmake a python calculatorinput calculator pythoncalculatrice in pythoncalculator on pythonpython program for simple calculator input given from command promptmake a calculator in python with defwrite a program to perform calculator operations in pythonhow to make a python calculatorbasic calculator which can perform 2 or 3 number calculations pythonhow to make a calculator in python using functionshow to make a calculator using idlepython calculasgenerate python function given input and output data online calculatormake a basic calculator in python calculator pyhtoncalc function in pythonpython simple calculator programcalculator code in python for calculator with pythonbuilding a calculator in pythonpython script for calculatorpython making a calculatorhigh end calculator in python from scratch calculator phythonhow to make a silmple calculaytor in pythoncode for calculatorpython code calculator with stepscalculator using functions in pythoncalculator in pythonbsmall python calculatorhow to make calculator with pythonptython code of calculatorhow to code calculator in python without functioncalculator basic in pythonpython program that creates estimatorrun calculator pythoncalculator code in python what is phython calculatorsimple calculator using function in pythonmaking a simple calculator python modulewrite menu based program in python to create a four way calculator1 create a calculator which can perform basic arithmetic operations depending upon the user input make calculator in python using funtionsimplement calculatorhow to make basic calculator in pythonmake calculator in pythoncalculator define pythoncalculate lcpd pythonwhat do you need to create a 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 how to make python calculator which calculates two or 3 valuespython program to make simple calculatorcoding a simple calculator in pythoncalculator proggram script pythonhow to know the ammount of calculations performed by python programcalculator in pythhow to do a calculator in pythonwap to model a simple calculator using functions for the following operationspython code calculatorpython input calculator with operatormake a simple calculator using python mathematical operations python calcultorsimple python program for calculatorhow to code a calculator in pythoncalculator in python3calculator coding in pythoncreate a calculator using pythonbasical calculator pythoncalculation program in pythoncreate a calculator in pythoncalculator python 3python input 28 29 to calculatordevelop a menu driven python program to design a simple calculator for arthematic and relational operatorpython calculator codeswww creating calculator by using pythonsimple calculator operations pythoncalculator making in pythoncalculater app in pythoncode for calculator in pythoncreate a calculator app with pythonhow to build a calculator python calculator onlinewriting a calculator on pythonmaking simple calculator with python with idlecalculator with custom function in pythonpython as a calculator codegenerating a calculator with pythonpython script calculatorsimple calculator docs pythonhow to create a simple calculator in pythoncode for a calculator in pythonpython calculator basic codepython calculatorcalculator script pythonpython module calculator programpython program to simple calculatorcalculator python source codecode for making calculator in pythonwriting a calculator in pythoncalculator using function in pythoncalculate in python and display in chow to create a calculator in pythonpython calculator functionhow to write calculator program in pythonsimple calculator using pythonhow to make a calculator python 2www building simple calculator with python videocalculator program in pythoncalculator pyhton projectcoding on a calculaotr in pythonpython calculator programsimple calculator in python using swithcerhow to make python calculatorpython interpreter as calculator codepython program to make calculatorpython calculatorpython calculator file line the programe should performe the operation selectedcalculator in python for beinersbasic calculator pythoncalculators that use pythonmaking calculator in pythoncalcualator with pythoncalculator python programonline python calculatorpython for complete calculatorcalculator define using function in pythonpython console calculatorhow to make a simple calculator using pythonwrite a calculator in pythonhow to make an calculator in pythonsimple calculator python scriptpython arithmic calcilatoralgorithm that reads in 2 integers and simulates multiplication using a loop and addition using pythoncode for calculator app in pythonbasic python calculatorpython calculator examplepython calculetor lagorithambuilding calculator pythonprogram calculatormake calculator pythobcalculator python codesimple python calculatorpython make calculatorhow to code calculator in pythonhow to make your own calculator softwaremaking a text based calculator in pythoncalculator script in pythonhow to make a calculator with pythonpython how to make a calculatorhow to make a calculator in pythoncalculator from pythonq1 create a calculator where user have a menu to perform addition 2f subtraction 2f multiplication 2f division 2f display tables using loops in python write calculator programhow to make a basic calculator in pythonsimple calculator program in pythonbasic calculator codehow to make a coucalator pythonbasic calculator in python using functionsonline calculator using pythonpython calculator scripthow to make a calculator in python for beginnerscalculator pythoncreating calculator in pythonpython program to basic calculatormake console calculator in pythonpython program to build calculatorhow to make a calculator using pythoncalculator python projectpythin calc packagepython function calculatorcalculatrice with pythonpython program to make a simple calculator 28using functions 29create calculator pythoncalculus calculator in pythonpython calculate 3fcalculator codes in pythonhow to solve basic calculator pythonhow to make a caclulator in pythonpython simple calculator expressioncreate basic calculator pythonpython code for calculatorcode for simple calculator in python without functionbasic calculator with pythoncalculator python 5cmake calculatrice using python how to build a calculator in python2 09python program to make a simple calculatorpython calchow to create calculator in pythoncomplication pyhton calculatorcalc in pythonhow to make a simple calculator in pythonsimple calculator application pythoncalculator that use python to programdo a calculator in pythoncode python calculatordo a calculator in pythocode to make a calculator in pythonpython build calculator stringcalculator pythonbuild a calculator in pythonpython 2f 2f on a calculartorpython simple calculator with functionscreate a calculator function pythonsimple calculator pythonwrite a python program to demonstrate basic calculator functionality using the concept of functions in python how to make a calcualtor pythonhow to have a calculating input in pythonhow to make a addition calculator in python calculator in pythonpython calculator script examplepython calculator anspython simple calculatorpython calculatorscalculator project in pythoncomputation code pythonhow to add a calculation in pythonwrite a python program to design a simple calculator 28using functions 29 how to make a caculator in pythonsimple calculator in python without functionhow to code a simple calculator in pythonhow to give input into calc exe using pythonhow to make calculator by using pythonhow to code a simple calculator in python using functionsdef function python calculationcalculator python scriptcreate your own calculator function pythoncalculator programhow to do calculations with pythonpython estimator programmake calculator pythoncalculator in python codesimple calculator project in pythonmaking a full working calculator in pytonpytho calculatorpython calculator sample codevery basic python calculatorbasic calculator using pythonpython make a simple calculatormake calculator with pythoncalculator program pythoncreate a calculator in python tutorialcalculator code pythoncalculator in pythoncalculator on pyhotnbest calculator using pythonsimple basic calculator with pythonsimple computation pythonpython code for calculator downloading filehow to make a calculator inpyhow to make python calculatecalculator using pythonhow to create a calculator in python