Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 ) Write a function get _ continued _ fraction ( lst ) which given a list of numbers [ 0 , . . .

1) Write a function get_continued_fraction(lst) which given a list of numbers [0,...,1]
computes the continued fraction:
10+11+12+1+11
Your function should return a pair of integers (,)
where !=0
.
For example: get_continued_fraction([1,2,2]) should return (5,7)
Python code:
def get_continued_fraction(lst):
assert len(lst)>=1
(n4, d4)= get_continued_fraction([5])
print(f'Test # 0: {n4}/{d4}')
assert n4==1 and d4==5
(n1, d1)= get_continued_fraction([1,2,2])
print(f'Test # 1: {n1}/{d1}')
assert n1==5 and d1==7
(n2, d2)= get_continued_fraction([1,2,1,2,1])
print(f'Test # 2: {n2}/{d2}')
assert n2==11 and d2==15
(n3, d3)= get_continued_fraction([1,1,1,1,1,1])
print(f'Test # 3: {n3}/{d3}')
assert n3==8 and d3==13
2) Write a function make_continued_fraction(a, b) given numerator a and denominator b wherein 0<<= that returns a list [0,...,1] corresponding to the continued fraction representation of
.
Python code:
def make_continued_fraction(a, b):
assert a >0
assert a <= b
# your code here
continued_fraction =[]
while b !=0:
quotient = b // a
remainder = b % a
continued_fraction.append(quotient)
a, b = remainder, a
return continued_fraction
f1= make_continued_fraction(197,1024)
print(f'197/1024= ContinuedFraction({f1})')
assert f1==[5,5,19,2]
f2= make_continued_fraction(64,128)
print(f'64/128= ContinuedFraction({f2})')
assert f2==[2]
f3= make_continued_fraction(1,1)
print(f'1/1= ContinuedFraction({f3})')
assert f3==[1]
f4= make_continued_fraction(314157,1000000)
print(f'314157/1000000= ContinuedFraction({f4})')
assert f4==[3,5,2,5,1,7,1,2,3,2,1,15]

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

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions

Question

Ensure continued excellence in people management.

Answered: 1 week ago

Question

Enhance the international team by recruiting the best people.

Answered: 1 week ago