The word eval is actually abbreviated to evaluate. This practical function receives a string as input, evaluates that input and returns its equivalent value.
To make the calculator as simple as possible, we can use this function as follows:
x = input()
print(eval(x))
Important point: The above program, written in two lines, is very simple and understandable, but this function creates a big security problem in the program. The eval function can receive any string, so if the user enters malicious code in the input, the program will execute that code! For example, if the user wants to get the list of files on the system, change the value of the variables, see the directories, etc, the program will do this.
For example, the program also executes the following command:
__import__('os').system('dir')
Therefore, it is better to use eval in the following way in the calculator program to avoid the possible risks of this function:
def calc(x,y,op):
return eval(f"{x} {op} {y}")
print(calc(4,5,"+"))