Question: Need help in Python. Thanks! 6.52 LAB: Functions as objects: A Simple Calculator Grammar Write a function do_calc() capable of evaluating a binary arithmetic operation

Need help in Python. Thanks!

Need help in Python. Thanks! 6.52 LAB: Functions as objects: A SimpleCalculator Grammar Write a function do_calc() capable of evaluating a binary arithmetic

6.52 LAB: Functions as objects: A Simple Calculator Grammar Write a function do_calc() capable of evaluating a binary arithmetic operation on two function evaluations: f1(x) + f2(y) Your function should be able to handle these unary functions from the math module: sin, cos, exp, and log; as well as any binary arithmetic operation among '+', ''*', and 7.x and y are floating points and are assumed non-negative. Your function has a single parameter that is a character string of the following grammar: f1:x @ f2:y where f1 and f2 are single characters from (s,c,e,l) (corresponding respectively to sin, cos, exp, and log) and the '@'can be any of the specified arithmetic operators +,-,*,/. Your function needs to return the single floating point result of the operations. The above grammar does not permit whitespace on either side of each colon but does permit whitespace on either side of the operator. For example, if the user input is 5:0.5 - c:1.75 your function do_calc evaluates the expression sin(0.5) - cos(1.75) and returns 0.658 (Note sine and cosine expect arguments in radians.) The template below establishes two dictionaries that should prove useful. The first, F, is keyed by the characters s,c,e,l with values being the respective function objects from math. The second, o, is keyed by the characters +, *,/ with values being the respective binary operations that are function objects in the operators module). LAB ACTIVITY 6.52.1: LAB: Functions as objects: A Simple Calculator Grammar 0/10 main.py Load default template... 1 from math import sin, cos, exp, log 2 from operator import add, sub,mul, truediv 3 4 F={'s':sin,'c':cos, 'e':exp, 'l' log} 5 0={'+':add,'-':sub,'*':mul,'/':truediv} 6 Your code here; implement the function do_calc() 8 9 if name _main__': 10 text=input() 11 print(f'{do_calc(text):.3f}')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!