[pythonvis] Re: exercise discussion

  • From: "Jeffrey Thompson" <jthomp@xxxxxxxxxxx>
  • To: <pythonvis@xxxxxxxxxxxxx>
  • Date: Sun, 18 May 2014 09:59:30 -0400

Ivan and list listeners,

        1) Joseph is correct about using 0.6 as the multicand to get the
retailer's cost for the book.
This would mean that the retailer's profit is .4 * 24.95.
                One thing that these formulas do not necessarily provide is
an actual billing amount.
To provide this, you could use the built-in function: round().
In this particular case you would probably use retailers_cost =
round(amount, 2)
The amount would be the unrounded number, and the "2" is the number of
decimal places to round to . i.e. the number of digits to the right of the
decimal point.
The "2" in the round function above,
would round the value to the closest penny.
This is necessary because the retailer must pay a dollar and cents check for
the book(s).
Also his profit likewise must end up as a dollar and cents amount.
In my experience, the 2 most common applications of round are:
round(value, 0) to get the nearest whole number and round(value, 2) to get a
monetary value.

                2)As far as adding times is concerned, there are some "time"
types that would permit adding 2 times together.
James has posted that solution while was writing this!

        Take the time that you need for your round trip, and add it to the
value 6:52am.
By this I mean add the hours together, the minutes together, and the seconds
together.
For example, if your walking time is 2:45:36  hours, you would get
8:67:36 as the time amount.

        Step 2)divide the seconds value by 60.0 and take the integer portion
of the result and add it
to the minutes amount.
Put the remainder * 60 as the seconds amount.
        step3) divide the minutes value by 60 and process the value as
discussed in step 1.

        step3 If the number of hours exceeds 24 then
divide the hours value by 24 and take the integer portion and add it the
days variable.
Keep the fractional amount * 24 as your hours value.
So for example, 45:00:00 would be changed to:
day 1 21:00:00.
last step, change the military time from 21 hours to 9:00:00pm
To accomplish this, , do the following:

step A) if the hours value is > 12 hours, then subtract 12 from the hours
amount and add pm after the seconds if there are any.
step b) if the numbers is < 12 then type "A.M." after the seconds or end of
the last numbers in the time.
step c) if the numbers = 12, put "P.M." after the end of the time.

        Hope this helps.

        Jet

If anything I have written here is unclear, please let me know.

        Thanks,
        Jet


-----Original Message-----
From: pythonvis-bounce@xxxxxxxxxxxxx [mailto:pythonvis-bounce@xxxxxxxxxxxxx]
On Behalf Of Ivan Pivac
Sent: Sunday, May 18, 2014 6:03 AM
To: pythonvis@xxxxxxxxxxxxx
Subject: [pythonvis] exercise discussion

Hi everyone,

Since Thursday's learning room meeting, I have been working my way 
through the two exercises at the end of chapter 2 in the book, Think 
Like a Computer Scientist.  I wonder if if would be a a good idea to go 
through these two exercises, looking at the code and how best to produce 
the final output?

In the first task looking at the cost of retailing books, I resolved the 
problem, but, I wonder if my code could be more efficiently written.  
One question in this exercise is how to write the code where the retail 
cost of the book is $24.95 but the dealer receives a 40% discount.  My 
solution was:
24.95/10*6
however, the code didn't seem correct to me although the answer was 
after doing the maths on a calculator. .

In exercise two regarding what time a walker returned home, I have the 
total time taken to walk the distance but don't know how to add those 
minutes onto the time of 6.52 am.

Would it be worth while, I wonder, if the experts on the list could 
actually code the exercises as we work through them so that we can 
discuss the tasks on the learning room forum?  there may be several ways 
of producing the answer so examining those methods would also be an 
invaluable learning experience.  Meanwhile, I'll continue working on the 
home arrival time.



Regards
Ivan

-- 
Ivan Pivac
4271 Great North Rd
P O Box 69-203
Glendene
Auckland 0645
New Zealand
Tel: (64) 9 836-8876
Fax: (64) 9 836-4668
Email: ivan@xxxxxxxxxxxxx



---
This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com



Other related posts: