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

27th Mar 2022, 6:58 AM
Hi i
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!
27th Mar 2022, 7:49 AM
Ervis Meta
Ervis Meta - avatar
0
Could you tell me more about method 1?
27th Mar 2022, 8:14 AM
Hi i
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/
27th Mar 2022, 8:50 AM
Ervis Meta
Ervis Meta - avatar
0
I'm going to see if I did it right. Can you tell me the answer?
27th Mar 2022, 10:00 AM
Hi i