views:

126

answers:

2

Hi,

I have a script here (not my own) which calculates the length of a movie in my satreceiver. It displays the length in minutes:seconds

I want to have that in hours:minutes

What changes do I have to make?

This is the peace of script concerned:

if len > 0:
 len = "%d:%02d" % (len / 60, len % 60)
else:
 len = ""

res = [ None ]

I already got the hours by dividing by 3600 instead of 60 but can't get the minutes...

Thanks in advance

Peter

+3  A: 
hours = secs / 3600
minutes = secs / 60 - hours * 60

len = "%d:%02d" % (hours, minutes)
wallyk
Yeah, that worked! This little problem from a complete Python-noob is solved. Thanks to everybody!Peter
Peter
A: 

So len the number of seconds in the movie? That's a bad name. Python already uses the word len for something else. Change it.

def display_movie_length(seconds):
    # the // ensures you are using integer division
    # You can also use / in python 2.x
    hours = seconds // 3600   

    # You need to understand how the modulo operator works
    rest_of_seconds = seconds % 3600  

    # I'm sure you can figure out what to do with all those leftover seconds
    minutes = minutes_from_seconds(rest_of_seconds)

    return "%d:%02d" % (hours, minutes)

All you need to do is figure out what minutes\_from\_seconds() is supposed to look like. If you're still confused, do a little research on the modulo operator.

jcdyer