Hi all i am learning python and here in below code i am trying to making a simple calculator very basic but i need people of stackoverflow and help me guide me its working properly but my main concern is "return operator.get(operator_sign)(val1,val2)" this piece of code which is working fine but my question is, is this proper way or anything else should i do. And my another question is i need suggestions from all of you that how can i improve myself in code as i have heard be a smart coder we are not doing essay writing here.
from art import logo
print(logo)
def add(a,b):
return a+b
def sub(a,b):
return a-b
def mul(a,b):
return a*b
def div(a,b):
return a/b
def operation(val1,val2,operator_sign):
return operator.get(operator_sign)(val1,val2)
operator = {
"+": add,
"-": sub,
"*": mul,
"/": div,
}
val1 = int(input('Please provide your first input value:\n'))
val2 = int(input('Please provide your second input value:\n'))
operator_sign = input('What operation do you wish to perform\n"+" - Addition\n"-" - Subtraction\n"*" - Multiplication\n"/" - Division\n')
print(operation(val1,val2,operator_sign))