Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me with this one. And please make sure the codes work smoothly, I got answer that had errors. Thank you so much! 1.
Please help me with this one. And please make sure the codes work smoothly, I got answer that had errors.
1. Task Write a file named calculator.py that has a function binop which can evaluate strings representing simple binop accepts a single string parameter consisting of two positive integers and a singe operator between them, where the operator is one ofr/. There may also be arbitrarily many spaces before or after either number and/or the operator. The function returns the int or float value created by evaluating the expression. Python has several built-in ways to do this (eval, exec, com pile); do not use them. calculator.py also should not im port anything. 2. Example Invocations When you run calculator.py, nothing should happen. It defines a function, it does not run it. If in another file (which you do not submit) you write the following import calculator print (calculator.binop("111 10")) print(calculator.binop( print (calculator.binop( 12345/678")) print(calculator.binop( 965 you should get the following output: 1110 11+11 123 )) 18.207964601769913 842 3. Thought Questions How hard would it be to . Return the number if all there is is one number? Deal with negative numbers too, like -123 -456 Deal with a string with two operators, like 23 45 . Troubleshooting There are four operators that could be in the string, so you probably want four cases in a big if-elif-type statement Thank you so much!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started