simple python calculator

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

showing results for - "simple python calculator"
Noelle
12 Aug 2017
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()
Sasha
08 Jan 2021
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 
Valentina
01 Apr 2016
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
Martina
22 Mar 2018
1print("Enter Your Choice 1(Add)/2(Sub)/3(Divide)/4(Multiply)")
2num = int(input())
3if num == 1:
4    print("Enter Number 1 : ")
5    add1  = int(input())
6    print("Enter Number 2 : ")
7    add2 = int(input())
8    sum = add1 + add2
9    print("The Sum Is ", sum)
10elif num == 2:
11    print("Enter Number 1 : ")
12    sub1  = int(input())
13    print("Enter Number 2 : ")
14    sub2 = int(input())
15    difference = sub1 - sub2
16    print("The Difference Is ", difference)
17elif num == 3:
18    print("Enter Number 1 : ")
19    div1  = float(input())
20    print("Enter Number 2 : ")
21    div2 = float(input())
22    division = div1 / div2
23    print("The Division Is ", division)
24elif num == 4:
25    print("Enter Number 1 : ")
26    mul1 = int(input())
27    print("Enter Number 2 : ")
28    mul2 = int(input())
29    multiply = mul1 * mul2
30    print("The Difference Is ", multiply)
31else:
32    print("enter a valid Number")
Ethen
04 Mar 2016
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)
Lucia
24 Sep 2017
1def mutiply (x):
2    return 5*x
3o = mutiply(10)
4print(o)
queries leading to this page
creating a simple calculator in python python py make a calculatorpython calcualtorpython calculator code copy and pastecalculator pyhton projectpython as a calculator codepython calculator file linepython program to build calculatorpython simple calculator whith only integerwrite a python program to demonstrate basic calculator functionality using the concept of functions in python basic calculator in pythonuse built in calculator pythoncalculators that use pythoncalculate puc in pythoncalc function in pythonbuild a calculator using pythonhow to program a calculator in pythonmake calculator with pythonpython calculator codebasical calculator pythonmaking calculator in pythonsimple calculator in python using swithcerpython arithmic calcilatorpyhton calculatorhow to make python calculator which calculates two or 3 valueshow to create a calcualtor in python3python code for a working calculatorpython program to make simple calculatorpython code for calcculatorpython input calculatorcalculatrice with pythonhow make a calculator in pythonbuild simple calculator using pythonsimple calculator operations pythonpython 2c calorie calculatorsimple calculator with pythonwriting a calculator on pythonprograming a calculator to pythonpython function calculatorpython program to design a simple calculator 28using functions 29 calculator pyhtonlist calculator pythoncalculator python 3implement calculatorbuilding calculator pythoncalculaor with pythonpython code for calculatorpython calccalculator making in pythonuse in python calculationpython calculas programcoding on a calculaotr in pythonpython program to calculator top using functionbesic calculator in phytoncode for calculator app in pythoncalculatrice python codingcalculate function do in pythonimplement basic calculator python calculator in pythonhow to code a simple calculator in python using functionswhat do you need to create a python calculatorpython basic calculatorhow to make a python calculatorsimple calculator using pythonpython operator calculatorpython making a calculatorcalculator code python 3how to make a basic calculator in pythoncalculator in python for beinershow to make a simple calculator using pythoncreate a calculator from modules in pythonpython calculator exampleinput calculator pythonhow to create calculator in pythonfunction to calculate python making a text based calculator in pythonhow to make python calculatorhow to have a calculating input in pythonwrite a calculator code in pythonhow to make a addition calculator in pythoncalculator price in python using functionscalculator python tutorialpython program to create a calculatorcalculate lcpd pythonpython calculator program using main functionbest python calculatoronline calculator using pythonpython code calculator with stepspython calculatorpython simple calculator with functionspython calculator functioncalculator project in pythoncoucalator in pythonhow to code a working calculator in pythonpython calculetorcalculator on pythonmake calculator using functions in pythoncalculator python scriptcreating a calculator in pythonsimple calculator python 5ccalculator in python projectdo a calculator in pythonmake a simple calculator in pythoncode to make a calculator in pythonpython program for simple calculatorptython code of calculatorhow to make a calcultor in python using funtionarithmetic calculator pythonpython program to make calculatorcalculator with pythonpython calculator program on pythonhow to make a silmple calculaytor in pythoncreating calculator in pythonpython basic calculation between two numbershow to make a calculator pythoncalculus calculator in pythonpython calculator onlineonline python calculatorhow to add a calculation function in pythonsimple calculator command in pythonhow to make a calculator in python for beginnerscreate a calculator in pythoncalculator code in python for calculatrice in pythoncalculate x pythonbasic calculator which can perform 2 or 3 number calculations pythonmake a simple calculator using python mathematical operations write a python program to design a simple calculator 28using functions 29 code for making a calculator in pythonsimple calculator code in pythonpython calculator sample codebuilding calculator in pythonpython make calculatorbuild calculator with python2 09python program to make a simple calculatorbasic calculator with pythonbuilding a calculator in pythondef function python calculationcode for building calculator in pythonsimple python calculatorwrite a calculator in pythonpython program to make a simple calculator 28using functions 29what does calculate function do in pythoncode python calculatoroperations examples for calculator projecthow to make a calcualtor pythonpython program to basic calculatorcalculator basic in pythonpython calculator scripthow to make a boolean function in pythonpackages needed to build calculator pythonpython module calculatorpython calculatorcomputation code pythonpython calculator codescalculator on pyhotncalculator in python codecreate calculator in pythoncreate calculator using pythoncalculator in pythmake calculator in pythonpython calculator modulecalculator class pythoncalculator in python functioncalculator made with pythonbasic calculator pythonpython module calculator programpython ccalculetorcalculator syntax for pythonhow to make calculator by using pythoncalculator using pythonpython script for calculatorcreate calculator pythoncalculator python codemake a calculator with defining in pythonhow to make a calculator in python without defined functioncalculater app in pythonpython calculataorhow to give input into calc exe using pythonhow to make a calculator inpyhow to make a calculator in pythonsimple calculator project in pythonbasic python calculatorrun calculator pythonconstruct a python program to make a simple calculator how to add a calculation in pythoncalcaulator in pythoncode in python for calculatorrealtivebearing python calculatorcreate your own calculator function pythonmaking a calculator in python using functionsbuild a calculator in python forhow to do a calculator in pythonpython calculator display a menu with operation options inputsimple calculator python codepython code for calculator downloading filepython print calcwith what module can i create calculator in pythonbasic calculator using pythonhow to make a calculator in python simple beginnerpython calculator example with chekchow to make calculator in pythone xplainedwrite calculator app using pythonhow to code calculator in pythonpython projects using calculationspython simple calculator expressionhow to make calculation programs using configin pythoncalcualator with pythonpython calaculatorcalculator that use python to programtaking an operation as input how to calculate pythonbasic simple calculator in pythonhow to code a calculator in pythonhow to build a calculator in pytoncan you code a calculator in pythonhow to write calculator program in pythoncode for python calculatorsimple calculator in python using functionssimple basic calculator with pythoncalculate in python and display in cstrcutured package for calculator using pythonhow to create python calculatorcalculator code pythonmaking a calculator in pythonhow to make calculator in pythoncalculator program in pythonpython program for calculatorcalculatror pythonsimple calculator docs pythoncalc in pythoncreate a calculator using pythonpython code calculatorpython caculatorcode for making calculator in pythonhow to make a coucalator pythonpython list calculatorcalculator python code glebber code for a calculator in pythonmake a calculator in pythoncalculator pythonpython simple calculatorpython calculattorcode for simple calculator in python without functionmake calculator using pythonhow to code a simple calculator in pythoncode for calculatorbasic calculator in python using functionsvery basic python calculatorhow to make a calculator in pythonpython build calculator stringdevelop a menu driven python program to design a simple calculator python make a calculatorhow to create a calulator in pythonmake a caleculatoer in pythonimport calculator in pythoncalculator python source codesimple calculator in pythonpython program that creates estimatorhow to make calculator pythonpython calculator projectpython simple calculator programscript for calculator in pythoncalculator using functions in pythoncreate a calculator where user have a menu to perform addition 2f subtraction 2f multiplication 2f division 2f display tables using loops in python simple caculation pythonpython create function that calculatespython how to code a calculatorwrite menu based program in python to create a four way calculatorcreate calculator using 4 functionscode for calculator in pythoncalculator code in pythonhow to create a simple calculator in pythonbuild a calculator in pythonpythin calc packagepython calculator librarymake console calculator in pythonsimple calculator program in pythoncalculator questions program in pythoncalculator python programmake calculator python simple compute pythonpython code for a calculator the programe should performe the operation selectedpython calculator code displayhow to do calculator in pythonhow to code calculator in python without functionpython input 28 29 to calculatorsimple calculator using function in pythonhow to create a web based calculator with pythonhow to make a subtraction calculator in pythoncalculator coding in pythonbasic py calculatorpython calculator basic codeprogram calculatorcomplication pyhton calculatorhow to make a simple calcualator in pythonhow to make an calculator in pythonpython calculator ansmake a python calculator for ligningerwrite 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 do a calculator in pythopython program to simple calculatorvlsm calculator pythonpython console calculatorcalculatrice pythoncalculator in pythongenerate python function given input and output data online calculatorcalculator codes in pythonpython estimator programpython interpreter as calculator codepython how to make a calculatorcool calculators we can create with pythoncalculator algorithm pythonhow to make calculator with pythonhow to create a calculator in pythonpython script calculatorcalculator python 5ccalculator proggram script pythondoes python have calculatorc 2b 2b calculator program using python functionshow to make python calculatehow to use python as a calculatorcoding a simple calculator in pythonhow to calculate using pythoncoding onpython to create a simple calculatorcalculator in pythonbhow to make your own calculator softwarehow to code a python calculatormake a basic calculator in python write menu based program in python to create a calculatorpy calculator calculator phythonsimple python program for calculatorcod in python to make a simple calculatorsimple calculator pythonpython calculate 28 29how to create calculator app in pythonmethods in pythond clculationhomework 5 3a multiplication calculator pythonbest python calculatorsmake calculator pythobcalculator in python3calculator script pythonpython compiler example for calculationcalculator program pythonhow to build a calculator in pythonpython calculator add simplepython calculaor filesimple calculator python scripthow to make a simple python calculatorcalculation using functions pythoncalculator pythonhow to make a simple calculator in pythonhow to make simple calculator in pythonhow to write a calculator program in pythoncalculator excersise in pythonhow to make a calculator python 2write a program to create a simple calculator in python calculatord you can do with pythonhow to make a calculator using pythonhow to make a standard calculator in pythonpython calculator programhow to make a calcultor using funtion in python python calculator codeingsimple python calculator