I understand how I would type this in IDLE, but I don't really understand the math behind it. Specifically lines 8 and 11... Can someone walk me through this, so I can understand the basic math that's going on here?
# Get a number of seconds from the user.
total_seconds = float(input('Enter a number of seconds: '))
# Get the number of hours.
hours = total_seconds // 3600
# Get the number of remaining minutes.
minutes = (total_seconds // 60) % 60
# Get the number of remaining seconds.
seconds = total_seconds % 60
# Display the results.
print('Here is the time in hours, minutes, and seconds:')
print('Hours:', hours)
print('Minutes:', minutes)
print('Seconds:', seconds)
You seem to be confused about the modulo operator. See also the docs and / or this question / post for more details.
In short, the modulo operator divides and returns the remainder of the division or 0 in case there is no remainder.
Lets look at your example step by step:
So you have 3 hours and the decimal part specifies minutes and seconds.
You already know that you have 3 full hours thus you can remove it
which is the same as
So you got 3 hours, 15 minutes and half a minute which are actually 30 seconds. This is exactly what is returned by
Note also
//is the floor division (returns the chopped of integer part of the standard division/).