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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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):
''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
Transcribed Image 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
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Use of XOR function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education