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
1# try to run this in repl.it to get the better experience
2
3from replit import clear
4# from art import logo
5
6def add(n1, n2):
7 return n1 + n2
8
9def subtract(n1, n2):
10 return n1 - n2
11
12def multiply(n1, n2):
13 return n1 * n2
14
15def divide(n1, n2):
16 return n1 / n2
17
18operations = {
19 "+": add,
20 "-": subtract,
21 "*": multiply,
22 "/": divide
23}
24
25def calculator():
26 print(logo)
27
28 num1 = float(input("What's the first number?: "))
29 for symbol in operations:
30 print(symbol)
31 should_continue = True
32
33 while should_continue:
34 operation_symbol = input("Pick an operation: ")
35 num2 = float(input("What's the next number?: "))
36 calculation_function = operations[operation_symbol]
37 answer = calculation_function(num1, num2)
38 print(f"{num1} {operation_symbol} {num2} = {answer}")
39
40 if input(f"Type 'y' to continue calculating with {answer}, or type 'n' to start a new calculation: ") == 'y':
41 num1 = answer
42 else:
43 should_continue = False
44 clear()
45 calculator()
46
47calculator()
48
1num1 = input("Enter a Number : ")
2num2 = input("Enter a Number : ")
3result = (num1 * num2)
4print(result)
5# And then print out the result
1
2# Define variables for number inputs..
3num1 = int(input("Enter first number: "))
4num2 = int(input("Enter second number: "))
5
6# Input for operators
7op = input("Enter operator: ")
8
9# Functions for operations
10
11
12def add(num1, num2):
13 print('Result: ', num1 + num2)
14
15
16def subtract(num1, num2):
17 print('Result: ', num1 - num2)
18
19
20def multiply(num1, num2):
21 print('Result: ', num1 * num2)
22
23
24def division(num1, num2):
25 print('Result: ', num1 / num2)
26
27
28# Using the functions
29if op == '+':
30 add(num1=num1, num2=num2)
31elif op == '-':
32 subtract(num1=num1, num2=num2)
33elif op == '*':
34 multiply(num1=num1, num2=num2)
35elif op == '/':
36 division(num1=num1, num2=num2)
37else:
38 print('Invalid operator')
39
1#Calculator in python
2#No modules required
3qus = input('')
4if(qus=='ADDITON'):
5 no1 = int(input())
6 no2 = int(input())
7 print(no1+no2)
8
9if(qus=='MULTIPLICATION'):
10 no1 = int(input())
11 no2 = int(input())
12 print(no1*no2)
13
14if(qus=='DIVISION'):
15 no1 = int(input())
16 no2 = int(input())
17 print(no1/no2)
18
19if(qus=='SUBTRACTION'):
20 no1 = int(input())
21 no2 = int(input())
22 print(no1-no2)