Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

Time Exercises

  1. Return on Investment. Return on investment (ROI) is often stated on an annual basis. If you buy and sell stock over shorter or longer periods of time, the ROI must be adjusted to be a full year's time period. The basic calculation is as follows:

    Given the sale date, purchase date, sale price, sp, and purchase price, pp.

    Compute the period the asset was held: use time.mktime to create floating point time values for sale date, s, and purchase date, p. The weighting, w, is computed as

    w= (86400*365.2425) / (s-p)

    Write a program to compute ROI for some fictitious stock holdings. Be sure to include stocks held both more than one year and less than one year. See the section called “Stock Valuation” in Chapter 21, Classes for some additional information on this kind of calculation.

  2. Surface Air Consumption Rate. When doing SACR calculations (see Surface Air Consumption Rate, and the section called “Dive Logging and Surface Air Consumption Rate”) we've treated the time rather casually. In the event of a night dive that begins before midnight and ends after midnight the next day, our quick and dirty time processing doesn't work correctly.

    Revise your solution to use a more complete date-time stamp for the start and end time of the dive. Use the time module to parse those date-time stamps and compute the actual duration of the dive.


 
 
  Published under the terms of the Open Publication License Design by Interspire