Answered step by step
Verified Expert Solution
Link Copied!

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.
Thank you so much!
image text in transcribed
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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics Of A Networked World Semantics For Grid Databases First International Ifip Conference Icsnw 2004 Paris France June 2004 Revised Selected Papers Lncs 3226

Authors: Mokrane Bouzeghoub ,Carole Goble ,Vipul Kashyap ,Stefano Spaccapietra

2004 Edition

3540236090, 978-3540236092

More Books

Students also viewed these Databases questions