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
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()
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")
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
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)
1#You can change Text at Inputs
2
3num1 = float(input("Enter Firt Number:"))
4num2 = float(input("Enter Second Number"))
5
6result= 0
7op = str(input("Enter an op(operator)"))
8#Gets Input Type--------
9try:
10 #U can make this in while loop ;-)
11 if op=="+":
12 result = num1 + num2
13 else if op=="-":
14 result = num1 - num2
15 else if op=="*":
16 result = num1 * num2
17 else if op=="/":
18 result = num1 / num2
19 else:
20 print("Invalid Input")
21 print("The result is " + result)
22except ZeroDivisionError:
23 print("U cant do that")
24