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
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
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()
1num_one = int(input("Enter 1st number: "))
2
3op = input("Enter operator: ")
4
5num_two = int(input("Enter 2nd number: "))
6
7if op == "+":
8 print(num_one + num_two)
9elif op == "-":
10 print(num_one - num_two)
11elif op == "*" or op == "x":
12 print(num_one * num_two)
13elif op == "/":
14 print(num_one / num_two)
15
1#Simple python Calculator
2#Enter the first variable
3#then the operator
4#and finally the second variable, then the answer is printed.
5A = int(input("Enter your first number: "))
6operator = input("Which operation would you like to perform? (+, -, /, *, //, **): ");
7B = int(input("Enter your second number: "))
8#Addition
9if operator == "+":
10 ans = A + B
11 print(str(ans))
12#Subraction
13elif operator == "-":
14 ans = A - B
15 print(str(ans))
16#division
17elif operator == "/":
18 ans = A / B
19 print(str(ans))
20#Multiplication
21elif operator == "*":
22 ans = A * B
23 print(str(ans))
24#Integer division
25elif operator == "//":
26 ans = A // B
27 print(str(ans))
28#Exponent
29elif operator == "**":
30 ans = A ** B
31 print(str(ans))
32else:
33 print("wrong operator!")
34