Inform two totals of different hours and have as output the amount of hours between the two informed

Asked

Viewed 42 times

0

In this problem I cannot use any ready lib!!!!!

So, in Python 3, I must do what is asked, however, I’m having difficulties to implement this, until then I tried to calculate the differences of the two schedules (which are in the format HH:MM:SS) converting each excerpt (hours and min.) in seconds, but there are other conditions I can’t find. input examples:

1)23:59:59

02:40:00

2)21:10:00

21:07:01

exit

1)02:40:01

2)23:57:01

At the time, I was able to make the difference, but I had trouble getting out

time1 = (input())
time2 = (input())

hora1 = time1[0]+time1[1]
minuto1 = time1[3]+time1[4]
segundo1 = time1[6]+time1[7]

horareal1 = int(hora1)
minutoreal1 = int(minuto1)
segundoreal1 = int(segundo1)

hora2 = time2[0]+time2[1]
minuto2 = time2[3]+time2[4]
segundo2 = time2[6]+time2[7]

horareal2 = int(hora2)
minutoreal2 = int(minuto2)
segundoreal2 = int(segundo2)

if horareal1 > 23 or minutoreal1 > 59 or segundoreal1 > 59 or horareal2 > 23 or minutoreal2 > 59 or segundoreal2 > 59:
    exit()


if hora1 >= hora2:
    #p/hora1
    x = minutoreal1*60
    y = horareal1*3600
    z = x+y+segundoreal1

    #p/hora2
    x1 = minutoreal2*60
    y1 = horareal2*3600
    z1 = x1+y1+segundoreal2
    #subtraíndo p/hora

    segtotal = z-z1
    x2 = int(segtotal/3600)
    x22 = x2*3600
    #subtraído os segundos totais
    segtotal2 = segtotal-x22
    #subtraíndo p/minuto
    y2 = int(segtotal2/60)
    y22 = y2*60
    segtotal3 = segtotal2-y22


    print(x2,':',y2,':',segtotal3)
  • 3
  • If the project is important, why can’t you use packages that already do the work for you?

  • Limitation given by the teacher, no libs, unfortunately

  • 1

    So please edit the question and detail what you have already managed to do and what difficulties encountered in the process.

  • Okay, thanks, I’ll do it

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.