Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define a data type rational in rational.py that represents a rational number, ie, a number of the form a/b where a and b notequalto 0

image text in transcribed

Define a data type rational in rational.py that represents a rational number, ie, a number of the form a/b where a and b notequalto 0 are integers. The data type must support the following API: Use the private function _ged () to ensure that the numerator and denominator never have any common factors. For example the rational number 2/4 must be represented as 1/2. $ python rational.py 100 3.1359290356 import stdio import sys # Returns the GCD of p and q, computed using Euclid's algorithm. def _gcd(p, q): return p if q -- theta else _gcd(q, p % q) class Rational: Represents a rational number. def _init_(self, x, y-1): Constructs a new rational given its numerator and denominator. d = _gcd (x, y) self. _x = ... self, _y = ... def __add __(self, other); Return the sun of and other. def _sub _(self, other); Returns the product self and other. def __abs __(self); Return the absolute value of self. def __str __(self): Returns a string representation of self. A, b =self._, self. _y if a - a or b - 1: return str(a) if b

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions