Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Coding has to be in python language def gcd(m, n): while m % n != 0: oldm = m oldn = n m = oldn

image

Coding has to be in python language

def gcd(m, n): while m % n != 0: oldm = m oldn = n

m = oldn n = oldm % oldn

return n

class Fraction:

def __init__(self, top, bottom):

self.num = top # the numerator is on top self.den = bottom # thedenominator is on the bottom

def __str__(self): return str(self.num) + "/" +str(self.den)

def simplify(self): common = gcd(self.num, self.den)

self.num = self.num // common self.den = self.den // common

def __add__(self,otherfraction):

newnum = self.num*otherfraction.den+ self.den*otherfraction.num newden = self.den *otherfraction.den

f = Fraction(newnum, newden) f.simplify() return( f )

# define the mixed() method below

def main(): print("Create at least 2 Fraction objects and testyour mixed() method below")

if __name__ == "__main__": main()

Write a new method for the Fraction class called mixed () which returns a string that writes out the Fraction in mixed number form. Here are some examples: f1 Fraction (1, 2) print (f1. mixed()) f2 = Fraction (3, 2) print (f2.mixed()) f3 = Fraction (5, 1) print (f3.mixed()) # should print "1/2" # should return "1 and 1/2" # should return "5" Do not remove any of the provided functions, or alter them in any way. They are being used by the auto- grader, and any change to the existing functions and methods in the class will probably cause the auto- grader to fail.

Step by Step Solution

3.46 Rating (153 Votes )

There are 3 Steps involved in it

Step: 1

Python version 36 Python program to add and test the mixed method of Fraction class def gcdm n while ... 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

Microeconomics An Intuitive Approach with Calculus

Authors: Thomas Nechyba

1st edition

538453257, 978-0538453257

More Books

Students also viewed these Programming questions

Question

=+b) What might you consider doing next?

Answered: 1 week ago

Question

Calculate the missing value.

Answered: 1 week ago