num_one =int(input("Enter 1st number: "))
op =input("Enter operator: ")
num_two =int(input("Enter 2nd number: "))
if op =="+":
print(num_one + num_two)
elif op =="-":
print(num_one - num_two)
elif op =="*"or op =="x":
print(num_one * num_two)
elif op =="/":
print(num_one / num_two)
Posted by: Guest
on August-01-2020
1
calculator in python
# try to run this in repl.it to get the better experience
from replit import clear
# from art import logodefadd(n1, n2):
return n1 + n2
defsubtract(n1, n2):
return n1 - n2
defmultiply(n1, n2):
return n1 * n2
defdivide(n1, n2):
return n1 / n2
operations = {
"+": add,
"-": subtract,
"*": multiply,
"/": divide
}
defcalculator():
print(logo)
num1 =float(input("What's the first number?: "))
for symbol in operations:
print(symbol)
should_continue =Truewhile 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}")
ifinput(f"Type 'y' to continue calculating with {answer}, or type 'n' to start a new calculation: ") =='y':
num1 = answer
else:
should_continue =Falseclear()
calculator()
calculator()
Posted by: Guest
on November-22-2020
Code answers related to "python simulate a four operations calculator"
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
Check Your Email and Click on the link sent to your email