Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please can you help me to solve this by using python This program takes two fractional inputs and produces an output in the form of

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

please can you help me to solve this by using python

This program takes two fractional inputs and produces an output in the form of fraction representation for any of the four arithmetic operations. The four operations are as follows: addition (+), subtraction (-), multiplication (*), and division (/). The general form of the fractional input is a/b $ c/d (note $ represents any one of the four operations) where a,b,c and d can take both positive and/or negative integers. Here are some of the two fractional inputs. All the entries shown below are of the correct form: 3/4--5/6 3/4 + 8/9 3/4 - 8/9 3/4 * 8/9 3/4/8/9 -3/4 + 8/9 -3/4 - 8/9 -3/4 * 8/9 -3/4/8/9 -3/4 --8/9 -3/4* -8/9 -3/4/-8/9 Here are some of the wrong entries of the two input fractional numbers that the user will be informed of the error and request the user to enter again two fractional numbers. The user is given only 3 consecutive tries. 3/4 - + 5/6 3/4 + + 5/6 3/4* +5/6 3/4/5/6 Four functions are to be created in this assignment. They are coeffAndSign, addSubtract, multiDivide, reduceForm. These four functions, where each function is designed to carry out specified task. The function coeffAndSign processes the input send from the calling program. The addSubstract takes in 5 arguments and will compute the addition or subtraction of the two-input fractional operation. Similarly, the function multiDivision will act accordingly to the rules established in computing two input fractional numbers. def coeffAndSign (input) The fractional inputs a/b $ c/d ($ refers to any one of the four arithmetic operators (+,-*,7). This function will determine a, b, c, d and one of the operators (+-*/) from the input and returns them. For example, the user enters the following input in the calling program: 3/4 + 1/2, then def coeffAnd Sign(input) returns obtain the following values 3,4,1,2 back to the calling program. If the input was of incorrect form, the user will be prompted to reenter the input and will be given 3 tries. def addSubtract(a,b,c,d,op) The function receives 5 arguments from the calling program. The string op denotes either add or subtraction operation. The function then returns a fractional solution that comprises numerator and denominator back to the calling function. The outputs are then printed as a fractional number de multiDivision ab,c,d,op) The function receives 5 arguments from the calling program. The string op denotes either multiply or division operation. The function then returns a fractional solution that comprises numerator and denominator back to the calling function. The outputs are then printed as a fractional number. def reduceForm(num,den) The function takes in two arguments and reduce will reduce the output to the lowest fractional form. Here are some examples: 14/12 = 7/6 3/7 = 3/7 -18/12 = -3/2 Your program layout def coeffAndsign (input) return a, b, c, d, op def addSubtract(a,b,c,d,op) Y+ = 4/ return numerator, denominator # can use any variable of your choice def multiDivision(a,b,c,d,op) return numerator, denominator # can use any variable of your choice return reduceNum, reduceDen 16 ta ad tbc bxd #calling program (consider as the main program) Read an input (example. 3/4 +1/2) Input = read 'Enter an input:) ( 8% + 3/4 = 20+21 call the function coeffAndSign (input) abcd op = coeffAndsign(input) call either function addsubtract(a,b,c,d,op) or function multiDivision(a,b,c,d,op) Do an if test on op, it will determine which one of them you need to select. 41 78 num den=addSubtract(a,b,c,d,op) or num den = multiDivision (a,b,c,d,op) call the function reduceForm(num,den) reduceNum reduceDen = reduceForm(num,den) (4.6): 4% = print ('The result is 'reduceNum', reduceDen) This program takes two fractional inputs and produces an output in the form of fraction representation for any of the four arithmetic operations. The four operations are as follows: addition (+), subtraction (-), multiplication (*), and division (/). The general form of the fractional input is a/b $ c/d (note $ represents any one of the four operations) where a,b,c and d can take both positive and/or negative integers. Here are some of the two fractional inputs. All the entries shown below are of the correct form: 3/4--5/6 3/4 + 8/9 3/4 - 8/9 3/4 * 8/9 3/4/8/9 -3/4 + 8/9 -3/4 - 8/9 -3/4 * 8/9 -3/4/8/9 -3/4 --8/9 -3/4* -8/9 -3/4/-8/9 Here are some of the wrong entries of the two input fractional numbers that the user will be informed of the error and request the user to enter again two fractional numbers. The user is given only 3 consecutive tries. 3/4 - + 5/6 3/4 + + 5/6 3/4* +5/6 3/4/5/6 Four functions are to be created in this assignment. They are coeffAndSign, addSubtract, multiDivide, reduceForm. These four functions, where each function is designed to carry out specified task. The function coeffAndSign processes the input send from the calling program. The addSubstract takes in 5 arguments and will compute the addition or subtraction of the two-input fractional operation. Similarly, the function multiDivision will act accordingly to the rules established in computing two input fractional numbers. def coeffAndSign (input) The fractional inputs a/b $ c/d ($ refers to any one of the four arithmetic operators (+,-*,7). This function will determine a, b, c, d and one of the operators (+-*/) from the input and returns them. For example, the user enters the following input in the calling program: 3/4 + 1/2, then def coeffAnd Sign(input) returns obtain the following values 3,4,1,2 back to the calling program. If the input was of incorrect form, the user will be prompted to reenter the input and will be given 3 tries. def addSubtract(a,b,c,d,op) The function receives 5 arguments from the calling program. The string op denotes either add or subtraction operation. The function then returns a fractional solution that comprises numerator and denominator back to the calling function. The outputs are then printed as a fractional number de multiDivision ab,c,d,op) The function receives 5 arguments from the calling program. The string op denotes either multiply or division operation. The function then returns a fractional solution that comprises numerator and denominator back to the calling function. The outputs are then printed as a fractional number. def reduceForm(num,den) The function takes in two arguments and reduce will reduce the output to the lowest fractional form. Here are some examples: 14/12 = 7/6 3/7 = 3/7 -18/12 = -3/2 Your program layout def coeffAndsign (input) return a, b, c, d, op def addSubtract(a,b,c,d,op) Y+ = 4/ return numerator, denominator # can use any variable of your choice def multiDivision(a,b,c,d,op) return numerator, denominator # can use any variable of your choice return reduceNum, reduceDen 16 ta ad tbc bxd #calling program (consider as the main program) Read an input (example. 3/4 +1/2) Input = read 'Enter an input:) ( 8% + 3/4 = 20+21 call the function coeffAndSign (input) abcd op = coeffAndsign(input) call either function addsubtract(a,b,c,d,op) or function multiDivision(a,b,c,d,op) Do an if test on op, it will determine which one of them you need to select. 41 78 num den=addSubtract(a,b,c,d,op) or num den = multiDivision (a,b,c,d,op) call the function reduceForm(num,den) reduceNum reduceDen = reduceForm(num,den) (4.6): 4% = print ('The result is 'reduceNum', reduceDen)

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

Step: 3

blur-text-image

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

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions