0
Help meā¦
Enter two integers and operators from the user and create a program that corresponds to the operator you entered. (You create a program to calculate any of the operators (+,-,*) that are entered.) integer input:5 operator input:+ integer input:3 5+3=8
4 Answers
0
Is easy:
# method 1: using `unsecured` eval()
printk(eval(input('Enter: ')))
# method 2: without using eval()
e = input('Enter two numbers separated with a space: ').split()+list(input('Enter the operator: '))
k = lambda a='0',b='0',o='+':(a:=int(a),b:=int(b),o:=o if o in'+-/*'else'Operator is not set')and(a+b if o=='+'else a-b if o=='-'else (a/b if a!=0 and b!=0 else 0) if o=='/'else a*b if o=='*'else o)
print(k(*e))
#method 3: your own method!
0
Could you tell me more about method 1?
0
eval() is a function that can interpret a pythonic syntax piece of code but as so it carries some dangerous issues with it.
For more you can see this link:
https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-eval-function/
0
I'm going to see if I did it right. Can you tell me the answer?