simple calculator in python

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

showing results for - "simple calculator in python"
Joni
21 Mar 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()
Anton
20 Feb 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 
Giacomo
20 Nov 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!!!')
Tommaso
23 Aug 2016
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  
Trenton
04 Jan 2017
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()
Nicola
16 Feb 2018
1#Simple Calculator Program in Python by Rupesh Singh
2
3def sum1(first_input, second_input):    # Sum function "+"
4    result1 = first_input + second_input
5    print("Your Answer is:-", result1)
6    return
7
8def minus(first_input, second_input):    # Minus function "-"
9    result2 = first_input - second_input
10    print("Your Answer is:-", result2)
11    return
12
13def multi(first_input, second_input):    # Multiplication function "*"
14    result3 = first_input * second_input
15    print("Your Answer is:-", result3)
16    return
17
18def div(first_input, second_input):    # Division function "/"
19    result4 = first_input / second_input
20    result4 = float(round(result4))
21    print("Your Answer is:-", result4)
22    return
23
24# User Input
25first_input = int(input("Enter your 1st Input:- "))
26command = input("What you want to do (+, -, *, /):- ")
27second_input = int(input("enter your 2nd Input:- "))
28
29if command == "+":
30    sum1(first_input, second_input)
31elif command == "-":
32    minus(first_input, second_input)
33elif command == "*":
34    multi(first_input, second_input)
35elif command == "/":
36    div(first_input, second_input)
37else:
38    print("Command Error!")
queries leading to this page
creating a simple calculator in python python 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 pythoncalculators that use pythonuse built in calculator pythoncalc function in pythonbuild a calculator using pythonhow to make a calculator app in pythonpython calculator codemake calculator with pythonhow to build a calulator in pythonpython program for simple calculator input given from command promptbasical calculator pythoncalculation program in pythonmaking calculator in pythonimplement a calculator in pythnsimple calculator in python using swithcerpython arithmic calcilatorpyhton calculatorhow to make python calculator which calculates two or 3 valuespython code for a working calculatorpython program to make simple calculatorpython input calculatorcalculatrice with pythonhow make a calculator in pythonbuild simple calculator using pythonsimple calculator operations pythonmaking a full working calculator in pytonsimple calculator with pythonhow to make a muliple number calculater in pythonwriting a calculator on pythonprograming a calculator to pythonpython code to creae a calculatorpython function calculatorpython program to design a simple calculator 28using functions 29 calculator python 3implement calculatorbuilding calculator pythonpython code for calculatorhigh end calculator in python from scratchpython calccalculator making in pythoncalculator idlemaking simple calculator with python with idleuse in python calculationpython calculas programcoding on a calculaotr in pythoncalculatrice python codingimplement basic calculator python calculator in pythonwhat do you need to create a python calculatorpython basic calculatorpython calculatorshow to make a python calculatorsimple calculator using pythonpython 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 examplearithmetic calculator in pythoninput calculator pythonhow to create calculator in pythonfunction to calculate python pyton calculator codemaking a text based calculator in pythonmake a calculator in python with defcalculator app in pythonhow to solve basic calculator 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 functionsbasic calculator codecode for making calculator in pythonpython program to create a calculatorcalculate lcpd pythoncalculator app pythonpython calculator program using main functiononline calculator using pythonpython code calculator with stepspython calculatorpython simple calculator with functionspython calculator functionhow to build a calculator calculator project in pythonpython as a calculator simple logic for calculatorcalculator on pythoncalculator python scriptcreating a calculator in pythondo a calculator in pythoncode to make a calculator in pythonpython program for simple calculatorptython code of calculatorpython make a simple calculatorarithmetic calculator pythonhow to make a calcultor in python using funtionpython program to make calculatorcalculator with pythonpython calculator program on pythonhow to make a silmple calculaytor in pythoncreating calculator in pythonhow to write calculations in pythonhow to make a calculator pythoncalculus calculator in pythonpython calculaspython calculator onlineonline python calculatorhow to make a simple calculator program with python and gladehow 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 calculate 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 simple calculator code in pythonpython calculator sample codebuilding calculator in pythonpython 2f 2f on a calculartorcreate basic calculator pythonpython make calculatorbuild calculator with python2 09python program to make a simple calculatorbasic calculator with pythonhow to make a calculator using idlebuilding a calculator in pythonpython calculator script exampledef function python calculationpython programs on calculatorcalculatore pythonsimple python calculatorwrite a calculator in pythonpython program to make a simple calculator 28using functions 29code python calculatoroperations examples for calculator projecthow to make a calcualtor pythonpython program to basic calculatorpython calculator scriptcalculator basic in pythonbuild a calculator with pythoncreate a calculator app with pythonpackages needed to build calculator pythonpython module calculatorpython calculatorcomputation code pythonpython calculator codescalculator on pyhotncalculator in python codecreate calculator in pythonwhat is phython calculatorcalculator in pythmake calculator in pythonpython calculator modulebest calculator using pythoncalculator made with pythonbasic calculator pythonpython module calculator programcalculator syntax for pythonhow to make calculator by using pythoncalculator using pythonpython script for calculatorcreate calculator pythonmake calculator in python using funtionscalculator python codecalculater app in pythonpython calculataorhow to give input into calc exe using pythoncalclator python codrhow 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 calculatorcreate your own calculator function pythonmaking a calculator in python using functionshow to do a calculator in pythonhow to do calculations with pythonsimple calculator python codepython calculator display a menu with operation options inputmake a custom form calculator pythonmaking a simple calculator python modulepython code for calculator downloading filewww building simple calculator with python videomaking a python calculatorhow to make a calculator in python using functions1 create a calculator which can perform basic arithmetic operations depending upon the user input basic calculator using pythonhow to know the ammount of calculations performed by python programhow to make calculator in pythone xplainedhow to code calculator in pythonpython simple calculator expressioncalcualator with pythoncalculator that use python to programhow to make a caculator in pythontaking an operation as input how to calculate pythonhow to code a calculator in pythonhow to build a calculator in pytoncan you code a calculator in pythonhow to write calculator program in pythoncalculator evolution idlecode for python calculatorsimple calculator in python using functionspython calculator code downloadsimple basic calculator with pythoncalculate in python and display in chow to create python calculatorcalculator using function in pythoncalculator 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 pythonhow to make a calculator in python source codepython code calculatorhow to make a coucalator pythonpython list calculatorcode for a calculator in pythonmake a calculator in pythonpython simple calculatorcalculator pythoncode for simple calculator in python without functionmake calculator using pythonhow to code a simple calculator in pythoncode for calculatorbasic calculator in python using functionspython 3 course calculatorvery basic python calculatorhow to make a calculator in pythonpython build calculator stringpython make a calculatorhow to create a calulator in pythoncreate a calculator in python tutorialpython calculate operation by secondcalculator python source codesimple calculator in pythonpython calculator project code pdfpython program that creates estimatorhow to make calculator pythonpython program make calculatorpython simple calculator programscript for calculator in pythoncalculator using functions in pythonsimple caculation pythonpython create function that calculateshow to make an ode calculator pythonwrite menu based program in python to create a four way calculatorhow to make a calculator in python sim0oecode for calculator in pythonhow to create a simple calculator in pythoncalculator code in pythonbuild a calculator in pythonpythin calc packagemake console calculator in pythonsimple calculator program in pythoncalculator questions program in pythoncalculator python programcreate bsaic calculator pythonmake calculator pythonpython code for a calculator the programe should performe the operation selectedpython script for a calculatorhow to do calculator in pythonhow to code calculator in python without functioncalculator module pythonpython input 28 29 to calculatorhow to create a calculator in python3simple calculator using function in pythonhow to open and operate calculator with pythoncalculator coding in pythonpython calculator basic codeprogram calculatorpytho calculatorcomplication pyhton calculatorhow to make an calculator in pythonpython calculator answrite 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 calculatorpython console calculatorcalculator in pythongenerate python function given input and output data online calculatorcalculator codes in pythoncalculator script in pythonpython estimator programpython interpreter as calculator codepython how to make a calculatorpython calculate 3fcool calculators we can create with pythoncalculator algorithm pythonhow to make calculator with pythonhow to create a calculator in pythonsimple calculator in python without functionpython script calculatorcalculator python 5calgorithm that reads in 2 integers and simulates multiplication using a loop and addition using pythoncalculator proggram script pythondoes python have calculatorhow to make python calculatehow to use python as a calculatorcoding a simple calculator in pythoncalculator in pythonbhow to make your own calculator softwaremake the best calculator in pythonhow to code a python calculatormake a basic calculator in python calculator phythonpython input calculator with operatorsimple python program for calculatorpython for complete calculatorsimple calculator pythonhow to create calculator app in pythonmake calculatrice using python python tutorial how to build a calculatorhomework 5 3a multiplication calculator pythonbest python calculatorsmake calculator pythobhow to make a calculator with pythoncalculator in python3calculator script pythonpython simple variable calculatorsymple calculator program using pythoncalculator programcalculator program pythonhow to build a calculator in pythonsimple calculator python scripthow to make a simple python calculatorcalculator pythonhow to make a simple calculator in pythonhow to make simple calculator in pythonhow to write a calculator program in pythoncalculator excersise in pythonwrite a program to create a simple calculator in python calculatord you can do with pythonmake a python calculatorhow to make a calculator using pythonpython calculator programsimple calculator in python