calculator python

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

showing results for - "calculator python"
Kahina
29 Jan 2020
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 
Jeb
18 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()
Isaac
19 Feb 2018
1import math 
2def SquareRoot (x):
3   return math.sqrt(x)
4  
5
6def lcm(x, y):  
7   
8    if x > y:  
9        greater = x  
10    else:  
11        greater = y  
12    while(True):  
13        if((greater % x == 0) and (greater % y == 0)):  
14            lcm = greater  
15            break  
16        greater += 1  
17    return lcm  
18
19def hcf(a,b):
20    H=a if a<b else b
21    while H>=1:
22        if a%H==0 and b%H==0:
23            return H
24        H-=1
25     
26
27def add(x, y):
28    return x + y
29
30
31def subtract(x, y):
32    return x - y
33
34
35def multiply(x, y):
36    return x * y
37
38
39def divide(x, y):
40    return x / y
41
42
43print("Select operation.")
44print("1.Add")
45print("2.Subtract")
46print("3.Multiply")
47print("4.Divide")
48print("5.lcm")
49print("6.SquareRoot")
50print("7.hcf")
51
52
53while True:
54    
55    choice = input("Enter choice(1/2/3/4/5/6/7): ")
56
57    
58    if choice in ('1', '2', '3', '4','5','7'):
59        num1 = float(input("Enter first number: "))
60        num2 = float(input("Enter second number: "))
61
62        if choice == '1':
63            print(num1, "+", num2, "=", add(num1, num2))
64
65        elif choice == '2':
66            print(num1, "-", num2, "=", subtract(num1, num2))
67
68        elif choice == '3':
69            print(num1, "*", num2, "=", multiply(num1, num2))
70
71        elif choice == '4':
72            print(num1, "/", num2, "=", divide(num1, num2))
73        
74        elif choice == '5':
75          print("The L.C.M. of", num1,"and", num2,"is", lcm(num1, num2)) 
76
77        elif choice == '7':
78          print("The H.C.F of", num1,"and", num2,"is", hcf(num1, num2)) 
79
80        
81        next_calculation = input("Do you want to do another calculation (yes/no): " )
82        if next_calculation == "no":
83          break
84
85    elif choice in ('6'):
86        num0 = float(input("Enter a number: "))
87        
88        if choice == '6':
89            print("The SquareRoot of ",num0,"is",SquareRoot(num0))
90
91    else:
92        print("Invalid Input")
Valerio
30 Apr 2017
1#this is a fraction calculator
2def fractions_regular(fractions):
3    f1 = input(13,25)
4    f1 = fractions.Fraction(f1)
5    f2 = input(6,25)
6    f2 = fractions.Fraction(f2)
7    operation = input('what is your iperation?')
8    if operation == '+':
9        print('{} + {} = {}'.format(f1, f2, f1 + f2))
10    if operation == "-":
11        print('{} - {} = {}'.format(f1, f2, f1 - f2))
12    if operation == "*":
13        print('{} * {} = {}'.format(f1, f2, f1 * f2))
14    if operation == "/":
15        print('{} / {} = {}'.format(f1, f2, f1 / f2))
Valentín
19 Aug 2017
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
Kit
14 May 2018
1calculator in python : https://github.com/ElieLeHackeur/calculator/blob/main/main.py
queries leading to this page
basical calculator pythoncalculator in pythcalc in pythoncalculation in python how to make a simple calculator using pythonpythin calc packagewrite a python program to design a simple calculator 28using functions 29 coding on a calculaotr in pythoncalculator python projectinput calculator pythonsimple caculation pythonbasic calculator pythonhow to make a calculator in python calculator phythonhow to run python calculator code the programe should performe the operation selectedsimple calculator docs pythoncalculator program in python using functionspython code for calculator downloading filepython calcbuilding calculator pythoncalculatrice with pythonpython as a calculator codepython in calculatorcalculators that use pythonpython code calculatorpython simple calculator expressionpython create function that calculatesmake calculator with pythonptython code of calculatorcreate a calculator function pythonpython script calculatorhow to make a calculator in pythonbasic calculator which can perform 2 or 3 number calculations pythoncalculator using python classeshow to create calculator in pythoncalculator module in pythonhow make a calculator in pythonsimple python calculatorcalculate in python and display in csimple calculator project in pythonhow to code calculator in pythoncalculator project in pythonhow to make a simple python calculatorhow to create a calculator in pythoncode to make a calculator in pythonpython program to make a simple calculator 28using functions 29generating a calculator with pythoncreate a calculator from modules in pythonwriting a calculator in pythoncalculator with pythonpython code for a working calculatorpython program to build calculatorcalculator coding in pythonmake calculator using pythoncalculadora pythoncode for python calculatorpython script for calculatorpython calculator sample codehow to have a calculating input in pythonbasic calculator in pythonpython program to make a calculatorscript for calculator in pythonbuild a calculator using pythonhow to make calculator in pythondo a calculator in pythowrite a program to create a simple calculator in python calculator code pythonmake a simple calculator in pythonbasic python calculatorcalculator python scriptpython module calculator programcalculator excersise in pythoncalculator in pythonbhow to make a silmple calculaytor in pythonpython calculator with classeshow to make calculator pytoncan you make a calculator with pythoncan you code a calculator in pythoncalculator code python 3calcaulator in pythonwhat do you need to create a python calculatorcalculator script pythonconstruct a python program to make a simple calculator calculate x pythonpython program for simple calculatorpython calculator codeshow to make a simple calculator using functions in pythonhow to code a calculator in pythonpython calculator examplehow to make a calculator in python for beginnershow to use python as a calculatorhow to make a simple calculator in pythonpython calculator codecreate calculator in pythonarithmetic calculator pythononline python calculatorcalculator algorithm pythonhow to do a calculator in pythonpython calculator programpython as a calculatorprograming a calculator to pythoncreate a calculator using pythonmake calculator pythobhow to code a python calculatorpython make a calculatorpython input 28 29 to calculatorpython calculator functioncode for making calculator in pythonmake a calculator in pythoncomplication pyhton calculatorhow to create calculator app in pythonpython calculator program on pythonpython calculator scriptmake calculator pythonmake a basic calculator in python how to make a calculator pythonhow to add a calculation function in pythoncalculator codes in pythonpython program to simple calculatorcalculator coding pythonhow to do calculator in pythoncode for calculatorbuild calculator with pythonpython calcualtorpython making a calculatorpython code for calculatorcalculator making in pythonhow to build a calculator in pytonhow to make function calculator in pythoncalculator python source codewrite a calculator code in pythoncreate a calculator in pythonpython program to make calculatorpython list calculatorcalculator on pythonhow to make simple calculator in pythoncan you make a calculator using pythoncode calculator pythoncalculator that use python to programhow to give input into calc exe using pythonpython how to make a calculatorphython calculatorpython calorie calculatorcode calculatrice pythonfunction to calculate python how to create a simple calculator in pythonbuild a calculator in pythonwrite a calculator in pythonhow to use python on your calculatorhow to make calculator pythonsimple calculator using pythonsimple calculator program in pythonoperations examples for calculator projectsimple calculator in python using swithcerpython calculatorcalculator basic in pythoncalculator in python codecalculator program pythoncalculator program in python using functionpython simple calculator with functionsmaking a calculator in pythonpython calculator code copy and pastecode for a calculator in pythonpython input calculatorcalculator code in python for calculator codecalculator in pythonpython calculataorcode in python for calculatoronline calculator using pythonbuild simple calculator using pythonsimple calculator python scripthow to make your own calculator softwarehow to build a calculator in pythonpython calculator anscalculatord you can do with pythonpython calculator onlinecalculatror pythonhow to create python calculatorpython program to design a simple calculator 28using functions 29 write a python program for calculatorhow to make an calculator in pythoncreating a simple calculator in python python interpreter as calculator codehow to make a calculator using pythonhomework 5 3a multiplication calculator pythonpython program to basic calculatorpython simple calculator whith only integercalculator python 5ccreating a calculator in pythonsimple python program for calculatorcalculator python 3how to code calculator in python without functionsimple calculator in pythonhow to create a calulator in pythonhow to build a calculator in python calculator in pythonpython calculatorhow to make 22function calculator 22 in pythonmaking a calculator in python using functionshow to make a python calculatorcalculator pyhton projectcalculator pythoncalculator on pyhotnhow to write calculator program in pythoncalculatorhow to add a calculation in pythonpython calculator librarybasic calculator using pythonhow to make basic calculator in pythonwrite a python program to demonstrate basic calculator functionality using the concept of functions in python python module calculatorcalculator in python for beinerscalculator in python projectpython program to make simple calculatorpython basic calculatorcomputation code pythoncalculator using pythoncalculator code in pythontaking an operation as input how to calculate pythonhow to make a calculator in puthonmake a simple calculator using python mathematical operations python calculatiorcalculator in python3simple calculator using function in pythonpython program for calculatorcode for calculator in pythonpython simple calculatorcalculator source code in pythonpython program to create a calculatorcool calculators we can create with pythoncalculater app in pythoncalculator python codehow to make calculator with pythoncalculator syntax for pythonpythion calculatorhow to make a calcualtor pythonmake calculator in pythonpython calculator basic codepython calculator file linecalculator pythonpython 3 function calculatorcreate a function calculator in pythoncreate calculator pythonhow to make calculator by using pythoncalculator onlinemaking calculator in pythonpython arithmic calcilatorcalculator code using pythonuse in python calculationbuilding a calculator in pythonprogram calculatorcalculator in pyhtonpython code for a calculatorcalculator python programsimple calculator code in pythoncalc function in pythonhow to create a calculator program in pythoncalculator made with pythondo a calculator in pythonhow to make python calculator which calculates two or 3 valueshow to code a simple calculator in pythonpython program calculatorpackages needed to build calculator pythonpython simple calculator programpython function calculatorpython code to make a calculatorhow to make a basic calculator in pythoncoding a simple calculator in pythongenerate python function given input and output data online calculatorpython calculator display a menu with operation options inputhow to calculat in pythonpython calculas programhow to make a calculator inpymaking a text based calculator in pythonbasic calculator in python using functionssimple calculator command in pythonpython project on calculatorcalculator using functions in pythonimplement basic calculator pythoncode python calculatorpython as calculatordef function python calculationpython make calculatorbasic calculator with pythonrun calculator pythonsimple basic calculator with pythonsimple calculator with pythoncalculator that runs pythondoes python have calculatorpython program that creates estimatorsimple calculator operations pythonmaking a simple calculator in pythonpython 4 function calculatorcreate your own calculator function pythonbuilding calculator in pythonsimple calculator python codecalcualator with pythonpython build calculator stringcalculator program in pythoncalculator questions program in pythoncalculate lcpd pythonwriting a calculator on pythoncalculat pythonpyhton calculatorpython estimator programhow to make python calculatormake console calculator in pythonimplement calculatorsimple calculator python2 09python program to make a simple calculatorhow to write a calculator program in pythonuse built in calculator pythoncreating calculator in pythonbest python calculatorshow to make a coucalator pythonpython console calculatorcalculator python