I have solved problem 1 of Problem set 1: http://dpaste.com/hold/1370231/
I noticed an error of about 0.02 on my final amounts, and I think the error is from round just the printed values rather than the entire expressions. I also think it is unnecessary to re-declare the printed variables as 'float' after casting them as 'str' to print.
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
There are also two types of rounding errors in computers when dealing with floats. One is the decimal rounding errors you normally think of. However, the computer does not use 10 base math. It uses binary, which can also have rounding errors. This dual set of rounding errors is why floating point math is more an approximation than something exact.
the only comment i have is that it is not necessary to use float() in lines 12, 14, and 16.
balance, annRate, and pmtRate are floats (lines 1,2,3) - any calculations performed with these values will result in a float.
>>> type(0.10 / 12)
>>> type(25 - 1.2)
Very true. minPmt = pmtRate * balance makes minPmt a float if either of pmtRate or balance is a float,and in this case both are.
Many languages have automatic casting from lower to higher bit sized types. So a char will become an int automatically if needed, and so on, but not the reverse. This is called promotion. Static casting, where you do it by hand, is only needed always in languages where they are not only strongly typed but also have no dynamic casting at all. In the rest of the languages, it is only needed when dynamic won't work. At the same time, it is the most dangerous because you can static cast something to a type where it will not work and end up with an error or loss.
Not the answer you are looking for? Search for more explanations.
Ok. thank you two for clearing that up. I included be safe (redundant) so that the variable did not get stuck as a 'str' type.
I also played around and found that the rounding difference I had was due to the manner in which the round() function was used in my code vs. what must have been used in the example code. I put parentheses in different places to round less numbers.
Is there an accepted best practice for which and how many numbers to round in an expression? or does it make any difference?
It all comes down to accuracy. The later the rounding is, the more the accuracy.
don't round intermediate results
round the final result to the number of digits in the least precise number in all the calcs.
or round to a precision that makes sense