(Python) Using modulo to get the remainder from changing secs, to hrs and minutes
<p>I'm currently new to learning python and stumbled upon this problem: </p>

<blockquote>
  <p>Exercise 2-7 Get the Time
  Write an algorithm that reads the amount of time in seconds and then displays the equivalent
  hours, minutes and remaining seconds.
  â¢ One hour corresponds to 60 minutes.
  â¢ One minute corresponds to 60 seconds.</p>
</blockquote>

<p>Here's how I wrote it:</p>

<pre><code>def amount_time(t):
  h = t//3600
  m = int((t/3600 - h)*60)
  s = int(((t/3600 - h)*60 - m)*60)
  print("Number of hours:",h)
  print("Number of minutes:",m)
  print("Number of Seconds:", s)
amount_time(5000)
</code></pre>

<p>I was told there was an easier way to write it using modulo to get the remainder for the minutes and seconds, could someone help? Thanks!</p>

<p>Your calculation of minuts doesnt work correct, you use Modulo with the hours.
You could do the same with minutes as you did wirh seconds instead:</p>

<pre><code>m =     (t - h * 3600) // 60
s = int (t - h*3600 - m*60)
ms = int ((t - h*3600 - m*60 - s) * 1000) # milliseconds
</code></pre>

<p>and to build the result string there are better ways, f.e.</p>

<pre><code>print '{}:{}:{}.{}'.format(h,m,s,ms)
</code></pre>

<p>You find more ways and options to Format, if you look here:</p>

<p><a href="https://docs.python.org/2/library/string.html" rel="nofollow">python dokumentation for string formatting</a></p>

python modulo