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

Postby AdamLandau » Sat Nov 16, 2013 12:52 pm

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
AdamLandau
 
Posts: 8
Joined: Sat Nov 16, 2013 12:48 pm

Re: Hours, Minutes, Seconds to Seconds-Help

Postby stranac » Sat Nov 16, 2013 1:22 pm

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.
User avatar
stranac
 
Posts: 888
Joined: Thu Feb 07, 2013 3:42 pm

Re: Hours, Minutes, Seconds to Seconds-Help

Postby AdamLandau » Sat Nov 16, 2013 1:24 pm

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
AdamLandau
 
Posts: 8
Joined: Sat Nov 16, 2013 12:48 pm

Re: Hours, Minutes, Seconds to Seconds-Help

Postby stranac » Sat Nov 16, 2013 2:15 pm

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.
User avatar
stranac
 
Posts: 888
Joined: Thu Feb 07, 2013 3:42 pm

Re: Hours, Minutes, Seconds to Seconds-Help

Postby AdamLandau » Sat Nov 16, 2013 2:19 pm

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
AdamLandau
 
Posts: 8
Joined: Sat Nov 16, 2013 12:48 pm

Re: Hours, Minutes, Seconds to Seconds-Help

Postby stranac » Sat Nov 16, 2013 2:50 pm

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.
User avatar
stranac
 
Posts: 888
Joined: Thu Feb 07, 2013 3:42 pm

Re: Hours, Minutes, Seconds to Seconds-Help

Postby AdamLandau » Sat Nov 16, 2013 6:22 pm

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
AdamLandau
 
Posts: 8
Joined: Sat Nov 16, 2013 12:48 pm

Re: Hours, Minutes, Seconds to Seconds-Help

Postby Wommbatt » Sat Nov 16, 2013 11:32 pm

AdamLandau wrote:
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

Postby AdamLandau » Sun Nov 17, 2013 1:06 am

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.
Reason: Please stop quoting everything. It makes stuff hard to read.
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
AdamLandau
 
Posts: 8
Joined: Sat Nov 16, 2013 12:48 pm


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], metulburr and 2 guests