## Hours, Minutes, Seconds to Seconds-Help

This is the place for queries that don't fit in any of the other categories.

### Hours, Minutes, Seconds to Seconds-Help

So my teacher has given me a task on finding the hours,minutes and seconds to seconds but I physically cannot get it to work...Here's what I have at the moment:

Code: Select all
`#################################################### Hours, minutes, and seconds to seconds conversion formula# Students should enter function on the next lines.def time2seconds(hours,minutes,seconds):    hours = (hours * 3600)    minutes = (minutes * 60)    seconds = (seconds * 1)    total = "hours" + "minutes" + "seconds"    return total#################################################### Test Code# Students should not change this code.def test(hours, minutes, seconds):    print str(hours) + " hours, " + str(minutes) + " minutes, and",    print str(seconds) + " seconds totals to",    print str(total_seconds(hours, minutes, seconds)) + " seconds."`

Any help? With something not too complicated...Thanks!
Last edited by Mekire on Sun Nov 17, 2013 4:51 am, edited 1 time in total.
Reason: Lock.
PC Specs:

i5 4670K @ 4.1Ghz
8GB Corsair Vengance RAM
Gigabyte Z87-HD3
1TB S-ATAIII 6.0Gb/s
NVIDIA GeForce GTX 760 2GB
Zalman Z11 Case
Corsair 550W PSU

Posts: 8
Joined: Sat Nov 16, 2013 12:48 pm

### Re: Hours, Minutes, Seconds to Seconds-Help

Code: Select all
`total = "hours" + "minutes" + "seconds"`

total will be "hoursminutesseconds"

It looks like you wanted:
Code: Select all
`total = hours + minutes + seconds`
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: Hours, Minutes, Seconds to Seconds-Help

Ok so I changed it and realised that was silly of me, but I still get an unrecognized output:

Code: Select all
`Line 34: SyntaxError: bad input ('hours')`

This is my code at the moment:

Code: Select all
`def time2seconds(hours, minutes, seconds):    hours = (hours * 3600)    minutes = (minutes * 60)    seconds = (seconds * 60)    total = hours + minutes + seconds    return total`

This is line 34:

Code: Select all
`print 7 hours, 21 minutes, 37 seconds    `
PC Specs:

i5 4670K @ 4.1Ghz
8GB Corsair Vengance RAM
Gigabyte Z87-HD3
1TB S-ATAIII 6.0Gb/s
NVIDIA GeForce GTX 760 2GB
Zalman Z11 Case
Corsair 550W PSU

Posts: 8
Joined: Sat Nov 16, 2013 12:48 pm

### Re: Hours, Minutes, Seconds to Seconds-Help

Well that line is not valid python.

If you just wanted to print that as a string, put some quotes around it.
If you wanted something else, you'll need to explain what you want it to do...
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: Hours, Minutes, Seconds to Seconds-Help

I want to make it a function. So when I say:

Code: Select all
`print 7 hours 5 minutes 2 seconds`

It would print in secondss
PC Specs:

i5 4670K @ 4.1Ghz
8GB Corsair Vengance RAM
Gigabyte Z87-HD3
1TB S-ATAIII 6.0Gb/s
NVIDIA GeForce GTX 760 2GB
Zalman Z11 Case
Corsair 550W PSU

Posts: 8
Joined: Sat Nov 16, 2013 12:48 pm

### Re: Hours, Minutes, Seconds to Seconds-Help

It can't work like that.
You need to call the function you made:
Code: Select all
`print time2seconds(7, 5, 2)`
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: Hours, Minutes, Seconds to Seconds-Help

stranac wrote:It can't work like that.
You need to call the function you made:
Code: Select all
`print time2seconds(7, 5, 2)`

Sorted, thanks.
PC Specs:

i5 4670K @ 4.1Ghz
8GB Corsair Vengance RAM
Gigabyte Z87-HD3
1TB S-ATAIII 6.0Gb/s
NVIDIA GeForce GTX 760 2GB
Zalman Z11 Case
Corsair 550W PSU

Posts: 8
Joined: Sat Nov 16, 2013 12:48 pm

### Re: Hours, Minutes, Seconds to Seconds-Help

Code: Select all
`def time2seconds(hours, minutes, seconds):    hours = (hours * 3600)    minutes = (minutes * 60)    seconds = (seconds * 60)    total = hours + minutes + seconds    return total`

Before you turn this assignment in you may want to make this change:
seconds = (seconds * 60)
to
seconds = (seconds)

you don't need to do any math here, the seconds are already in the unit that you want
Wommbatt

Posts: 24
Joined: Thu Jun 13, 2013 2:15 pm

### Re: Hours, Minutes, Seconds to Seconds-Help

Its fine, its all done. Thank you for your input though, greatly appreciated.
Last edited by stranac on Sun Nov 17, 2013 1:11 am, edited 1 time in total.
PC Specs:

i5 4670K @ 4.1Ghz
8GB Corsair Vengance RAM
Gigabyte Z87-HD3
1TB S-ATAIII 6.0Gb/s
NVIDIA GeForce GTX 760 2GB
Zalman Z11 Case
Corsair 550W PSU