(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>This is just "out of my head", because I got no testing system I could use right now.</p>

<pre><code>def amount_time(t):
    print("Number of Seconds:", t % 60)
    print("Number of Minutes:", (t // 60) % 60)
    print("Number of Hours:", (t // 3600))
</code></pre>

<p>What "t % 60" does: </p>

<ol>
<li>take t, divide it by 60</li>
<li>remove everthing left of the dot</li>
<li>multiply with 60</li>
</ol>

<p>With numbers:</p>

<ol>
<li>5000 / 60 = 83.33333</li>
<li>=> 0.33333</li>
<li>0.33333 * 60 = 20</li>
</ol>

python modulo