Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

** Python ** Kindly answer all the parts. Part 1: Estimating the error Use IDLE to open up the file posted below Fill in the

** Python **

Kindly answer all the parts.

Part 1: Estimating the error

  • Use IDLE to open up the file posted below
  • Fill in the missing pieces of the code, as instructed in the file
  • Run the loop for 100 iterations.
  • Observe for how many numbers do you get the correct result
  • Remove the print statement IN the loop
  • Run the loop for 10, 100, and 1000 iterations.
  • Explore how the difference between what you should get and what you do get behaves as the number of iterations changes
  • Estimate how many iterations would be needed to have an error that is as large as the number you add. Include your explanation in the code file that you will submit.

Part 2: Estimating the scope of the problem

  • Using your code, find two more numbers between 0 and 1 for which there are also incorrect results for 100 iterations
  • Using your code, find two numbers for which the result is correct.
  • Do some research online to figure out the reason why some numbers that you add repeatedly end up in the correct result, and why some others are not. Add your explanation to the code file you will submit.

Part 3: One potential solution

  • Import the decimal package to your code
  • ADD to your file a second loop that does exactly the same as the first loop but now using a decimal number repeatedly. You will have to make sure that all operations are done using decimals
  • How does the error behave as you run the code for 10, 100, and 1000 iterations using decimals? Is it better or worse than using Pythons default floating datatype? Do some research on the decimal module, and figure out the reason for the result. Add your explanation in the code file and ensure that enough comments are added to the source code as well.

Submit the code file for Part 4 that includes your observations and explanation for Parts 1, 2, and 3 at the top as a comment. You should only submit a single python code file that includes the explanations for the different parts at the top of the file.

floatingPointIssuesStart.py

ADD COMMENTS AS APPROPRIATE

sum = 0 toAdd = .1 max = ENTER NUMBER OF ITERATIONS HERE

for i in range (0, max, 1): sum = sum + toAdd print(sum, i) ADD A PRINT STATEMENT HERE THAT PRINTS (WHEN THE LOOP IS FINISHED) THE NUMBER OF ITERATIONS, THE NUMBER YOU ADDED, THE SUM YOU CALCULATED, AND THE DIFFERENCE BETWEEN THE CORRECT RESULT AND YOUR SUM

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

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago