Advertisement
GastonPalazzo

Var y Cond - Ej-18

Apr 2nd, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. def validaYSuma(hora):
  2.  
  3.     for i in range(len(hora)):
  4.         hora[i] = int(hora[i])
  5.  
  6.     if -1<hora[2]<60 and -1<hora[1]<60 and -1<hora[0]<24:
  7.         print('\n'+str(hora[0])+':'+str(hora[1])+':'+str(hora[2])+'hs es un horario valido!')
  8.         #s
  9.         if (hora[2]+1)//60>0:
  10.             hora[2] += 1
  11.             hora[2] %= 60
  12.             #m
  13.             if (hora[1]+1)//60>0:
  14.                 hora[1] += 1
  15.                 hora[1] %= 60
  16.                 #h
  17.                 if (hora[0]+1)//24>0:
  18.                     hora[0] += 1
  19.                     hora[0] %= 24
  20.                 else:
  21.                     hora[0]+=1
  22.             else:
  23.                 hora[1]+=1
  24.         else:
  25.             hora[2]+=1
  26.  
  27.         for i in range(len(hora)):
  28.             hora[i] = str(hora[i])
  29.         r = hora
  30.     else:
  31.         r = 0
  32.         print('\nError: Horario no valido!\n')
  33.  
  34.     return r
  35.  
  36. #main
  37. print('|CALCULADOR DE SEGUNDO SIGUIENTE|\n')
  38. hora=validaYSuma(input('Ingrese hora de la forma "hh:mm:ss" (24hs): ').split(':'))
  39. if hora != 0:
  40.     print('\nHora en el segundo siguiente -> '+hora[0]+':'+hora[1]+':'+hora[2]+'hs.')
  41. print('\nFin de la ejecucion!\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement