Python Coding Problem- How To Convert Seconds Into Minutes, Hours, And Day?

Discussion in 'Python' started by lemonhead71, Oct 3, 2012.

  1. lemonhead71

    lemonhead71

    Joined:
    Oct 3, 2012
    Messages:
    3
    Likes Received:
    0
    I would like to create a program to convert seconds into minutes, hours, and day in python.

    my function:

    def time_values(total_seconds):
    number_of_minutes=total_seconds//60
    number_of_hours=total_seconds//3600
    number_of_days=total_seconds//86400
    return number_of_minutes, number_of_hours, number_of_days

    in another module:

    seconds=int(input('Enter the number of seconds:').strip())
    minutes=q2_functions.time_values(seconds)
    hours=q2_functions.time_values(seconds)
    days=q2_functions.time_values(seconds)
    print('{0} seconds is equal to {1} minute(s), {2} hour(s), and {3} day(s).'.format(seconds,minutes,hours,days))


    These are the outputs I got:
    Enter the number of seconds:86400
    86400 seconds is equal to (1440, 24, 1) minute(s), (1440, 24, 1) hour(s), and (1440, 24, 1) days(s)

    These are the outputs I want:
    86400 seconds is equal to 1440 minute(s), 24 hour(s), and 1 day(s).

    What am I doing wrong? Thanks for your help.
     
    lemonhead71, Oct 3, 2012
    #1
    1. Advertisements

  2. lemonhead71

    UoPTucson

    Joined:
    Jun 28, 2017
    Messages:
    5
    Likes Received:
    2
    Your function is returning a tuple, not a single value.
     
    UoPTucson, Jul 3, 2017
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.