Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78692
| References | <2p203aldkhli65bd9crd4ljbfuab0u90oc@4ax.com> |
|---|---|
| Date | 2014-10-05 01:07 +1000 |
| Subject | Re: A little more: decimal_portion |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14599.1412435262.18130.python-list@python.org> (permalink) |
On Sun, Oct 5, 2014 at 12:58 AM, Seymore4Head <Seymore4Head@hotmail.invalid> wrote: > A little more: decimal_portion > > Write a function that takes two number parameters and returns a float > that is the decimal portion of the result of dividing the first > parameter by the second. (For example, if the parameters are 5 and 2, > the result of 5/2 is 2.5, so the return value would be 0.5) > > http://imgur.com/a0Csi43 > > def decimal_portion(a,b): > return float((b/a)-((b//a))) > > print (decimal_portion(5,2)) > > I get 0.4 and the answer is supposed to be 0.5. Work out exactly what your program is doing, step by step. Print out the intermediate steps in the calculation, and compare what the program's doing to what you expect to be happening. What's (b/a)? What's (b//a)? What's (b/a)-((b//a))? ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A little more: decimal_portion Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-04 10:58 -0400
Re: A little more: decimal_portion Chris Angelico <rosuav@gmail.com> - 2014-10-05 01:07 +1000
Re: A little more: decimal_portion Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-04 11:16 -0400
Re: A little more: decimal_portion Chris Angelico <rosuav@gmail.com> - 2014-10-05 01:24 +1000
Re: A little more: decimal_portion Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-04 11:38 -0400
Re: A little more: decimal_portion Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-05 01:46 +1000
Re: A little more: decimal_portion Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-04 12:11 -0400
Re: A little more: decimal_portion wxjmfauth@gmail.com - 2014-10-05 00:14 -0700
csiph-web