Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We have learned that 2 is not rational. However,2 can be arbitrarily well approximated by rational numbers. The goal of this programming exercise is to

We have learned that 2 is not rational. However,2 can be arbitrarily well approximated by rational numbers. The goal of this programming exercise is to find the best approximation p/q 2 with 2 q 100, 000. Write a Python program that iterates through all these q values. For each q, use the reasonable constraint 1.4 < p/q < 1.5 to come up with a small set of integer candidates p for a good approximation. Your program should output the (p, q) for which p/q approximates 2 best. Your program must not contain hardcoded approximations to 2, other than the numbers 1.4 and 1.5, or use Math.sqrt() or equivalent.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions