Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



We are using here a powerful strategy for designing programs: wishful thinking. We haven't yet said how a rational number is represented, or how the functions numer , denom , and rational should be implemented. Even so, if we did define these three functions, we could then add, multiply, print, and test equality of rational numbers:
If you want to change selection, open document below and click on "Move attachment"

2.2 Data Abstraction
s the following three functions: rational(n, d) returns the rational number with numerator n and denominator d . numer(x) returns the numerator of the rational number x . denom(x) returns the denominator of the rational number x . <span>We are using here a powerful strategy for designing programs: wishful thinking. We haven't yet said how a rational number is represented, or how the functions numer , denom , and rational should be implemented. Even so, if we did define these three functions, we could then add, multiply, print, and test equality of rational numbers: >>> def add_rationals(x, y): nx, dx = numer(x), denom(x) ny, dy = numer(y), denom(y) return rational(nx * dy + ny * dx, dx * dy) >>> def


Summary

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

Details



Discussion

Do you want to join discussion? Click here to log in or create user.