In this question you’ll write six related recursive functions to do basic arithmetic. You’re given a starter filele, which is where you’ll write your functions, and also a test script that can check...


In this question you’ll write six related recursive functions to do basic arithmetic. You’re given a starter filele, which is where you’ll write your functions, and also a test script that can check if your functions arecorrectly implemented. Every function you design must be recursive, and must follow the constraintsoutlined below.(Think of this exercise as a bunch of recursion exercises, and about what arithmetic means, which you solveby using only a restricted set of tools. No one is suggesting this results in practical software; but practicewith recursion is good.


On the planet Moosetopia, the Moosetopian computer engineers have invented computers, but comparedto our computers they are very limited. Whereas we have computers that can do arithmetic, like addition,and multiplication in hardware, Moosetopian computers can not do such advanced arithmetic in hardware:they had to write a library to implement arithmetic.We’re going to simulate Moosetopian computers using simple Python functions. Moosetopian computerhardware can do three things with integers:


1. Add one to any integer


2. Subtract one from any integer


3. Check if a number is equal to zero


This means that Moosetopians have to write functions to do simple things like addition and multiplication.You will no doubt be tempted to use Python operators for addition, and the others. This is sensible forEarthling computers, but it does not allow you to understand how the Moosetopians write software.


Requirements


We have provided a starter flile, with three functions defined:


1.incr(a) This function adds one to a


2.decr(a)This function subtracts one from a


3.zero(a) This function returnsTrueifa= 0.


Your job will be to write functions implementing simple arithmetic operations like addition, multiplication,subtraction, and integer division.


Define the following functions, recursively:


•add(a, b): returns the sum of a and b.


•mult(a, b): returns the product of a and b.


•gt(a, b): returns True if ai s greater than b, and False otherwise.


•sub(a, b): returns the difference between a and b.


•quot(a, b): returns the result of integer division of a by b.


•rem(a, b): returns the remainder of integer division of a by b.


Note: Your functions must be recursive, and may not use normal Python operators like+,*,-,//,%,>,>=,==,etc


. You may not use for loops, while loops, or list comprehensions. No global variables, either.In completing this question, you may only use the three functions above (incr(),decr(),zero()), and any recursive function you define in this question, e.g, you’ll have to call add()when defning mult(). Becauserecursion requires conditionals, you may useand, or, not You may assume for convenience that the inputs to your functions will be non-negative.


def incr(a):<br>''Returns the next integer after a'..<br>return a + 1<br>def zero(a):<br>'''Returns True if a is zero'<br>return a == 0<br>def decr(a):<br>''Returns the integer before a'''<br>return a - 1<br>= Your work goes below this line<br>def add(a, b):<br>''Returns the sum of a and b'''<br># using only incr, decr, zero, and recursion<br>return o<br>def mult(a, b):<br>'''Returns the product of a and b'''<br># using only add, incr, decr, zero, and recursion<br>return o<br>def gt(a, b):<br>Returns True if a is an integer greater than b;<br>returns False otherwise'..<br># using only incr, decr, zero, and recursion<br>return o<br>def sub(a, b):<br>'''Returns the difference between a and b.<br>on ly works if b >= 0'<br># using only gt, incr, decr, zero, and recursion<br>return o<br>def quot (a, b):<br>''Returns the result of integer division of a by b'

Extracted text: def incr(a): ''Returns the next integer after a'.. return a + 1 def zero(a): '''Returns True if a is zero' return a == 0 def decr(a): ''Returns the integer before a''' return a - 1 = Your work goes below this line def add(a, b): ''Returns the sum of a and b''' # using only incr, decr, zero, and recursion return o def mult(a, b): '''Returns the product of a and b''' # using only add, incr, decr, zero, and recursion return o def gt(a, b): Returns True if a is an integer greater than b; returns False otherwise'.. # using only incr, decr, zero, and recursion return o def sub(a, b): '''Returns the difference between a and b. on ly works if b >= 0' # using only gt, incr, decr, zero, and recursion return o def quot (a, b): ''Returns the result of integer division of a by b'" # using only sub, gt, incr, decr, zero, and recursion return o def rem(a, b): '''Returns the remainder of integer division of a by b'' # using only sub, gt, incr, decr, zero, and recursion return o
Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here