calculator in python
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
Enter choice(1/2/3/4): 3
Enter first number: 15
Enter second number: 14
15.0 * 14.0 = 210.0
calculator in python
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
Enter choice(1/2/3/4): 3
Enter first number: 15
Enter second number: 14
15.0 * 14.0 = 210.0
calculator in python
# try to run this in repl.it to get the better experience
from replit import clear
# from art import logo
def add(n1, n2):
return n1 + n2
def subtract(n1, n2):
return n1 - n2
def multiply(n1, n2):
return n1 * n2
def divide(n1, n2):
return n1 / n2
operations = {
"+": add,
"-": subtract,
"*": multiply,
"/": divide
}
def calculator():
print(logo)
num1 = float(input("What's the first number?: "))
for symbol in operations:
print(symbol)
should_continue = True
while should_continue:
operation_symbol = input("Pick an operation: ")
num2 = float(input("What's the next number?: "))
calculation_function = operations[operation_symbol]
answer = calculation_function(num1, num2)
print(f"{num1} {operation_symbol} {num2} = {answer}")
if input(f"Type 'y' to continue calculating with {answer}, or type 'n' to start a new calculation: ") == 'y':
num1 = answer
else:
should_continue = False
clear()
calculator()
calculator()
calculator in python
def mutiply (x):
return 5*x
o = mutiply(10)
print(o)
Calculator in python
num1 = input("Enter a Number : ")
num2 = input("Enter a Number : ")
result = (num1 * num2)
print(result)
# And then print out the result
calculator in python
# Define variables for number inputs..
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
# Input for operators
op = input("Enter operator: ")
# Functions for operations
def add(num1, num2):
print('Result: ', num1 + num2)
def subtract(num1, num2):
print('Result: ', num1 - num2)
def multiply(num1, num2):
print('Result: ', num1 * num2)
def division(num1, num2):
print('Result: ', num1 / num2)
# Using the functions
if op == '+':
add(num1=num1, num2=num2)
elif op == '-':
subtract(num1=num1, num2=num2)
elif op == '*':
multiply(num1=num1, num2=num2)
elif op == '/':
division(num1=num1, num2=num2)
else:
print('Invalid operator')
calculator in python
#Calculator in python
#No modules required
qus = input('')
if(qus=='ADDITON'):
no1 = int(input())
no2 = int(input())
print(no1+no2)
if(qus=='MULTIPLICATION'):
no1 = int(input())
no2 = int(input())
print(no1*no2)
if(qus=='DIVISION'):
no1 = int(input())
no2 = int(input())
print(no1/no2)
if(qus=='SUBTRACTION'):
no1 = int(input())
no2 = int(input())
print(no1-no2)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us