Okay, I appreciate everyone's help!
i am trying to work out how to find a duration type thing.. i have created this as an example of what i am trying to do.

### gaining inputs
start= raw_input("What time did the tv show start: (Format = 14, 12) ")
finish= raw_input("What time did the tv show finish: (Format = 14, 12) ")

### attempting to turn the hours into mins, and adding them to the mins
m= start[0]*60+start[1]
n= finish[0]*60+finish[1]

### turning into intergers
m2= int(m)
n2= int(n)

### finding the tv show duration
duration= n2-m2

### prints the duration in mins of the tv show
print "TV Show Duration:" duration

raw_input("\n\nPress the enter key to exit.")

could someone please tell me what im doing wrong, and provide me with a fix?
this has being my biggest issue.
cheers.
jase.

Recommended Answers

All 7 Replies

m= start[0]*60+start[1]
n= finish[0]*60+finish[1]

here there is a problem, start[0] refers to the first character in the string start. so from your exmaple of 14, 12 start[0] would be 1. and start[1] would be 4. Also you would need to convert those to intergers before multiplying by 60 otherwise you will end up with

111111111111....60 of them.

Hope you can see where you are going wrong.

Chris

yeah that [0] was only there becuase there was a tuple in the previous versions of code

cheers guys,
i have changed the first issue, however converting the interger before i find the ammount of mins, i'm a little lost on?

here is how it stands

### gaining inputs
start= raw_input("What time did the tv show start: (Format = 14, 12) ")
finish= raw_input("What time did the tv show finish: (Format = 14, 12) ")

### attempting to turn the hours into mins, and adding them to the mins
m= start[1]*60+start[4]
n= finish[1]*60+finish[4]

### turning into intergers
m2= int(m)
n2= int(n)

print m2
print n2

### finding the tv show duration
duration= n2-m2

print duration

### prints the duration in mins of the tv show
print duration

raw_input("\n\nPress the enter key to exit.")

yea cheers for that paulthom, i didnt know what they meant, but now i do :)

You could always do something like this:

m= int(start[1])*60+int(start[4])
n= int(finish[1])*60+int(finish[4])

That will make M and N integers so you do not need to convert them at all but i did my own program to do the same thing to see if i could change anything and this is what i got:

def length(): #using a function
    print 'Please enter the start of the show in the format 03,16'
    start = raw_input(">")
    print "Please enter the end of the show in the format 03,16"
    end = raw_input(">")
    m = int(start[:2]) *60+int(start[3:])
    n = int(end[:2]) *60+int(end[3:])
    length = n-m
    print "the show lasted for %i minutes" %length


while True: 
    length()
    print "Press enter to restart and x to exit"
    f = raw_input()
    if f.lower() == 'x':
        break
    else:
        pass

LEGENDS!!
thanks everyone!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.