SHARE
TWEET

Untitled

a guest Jan 12th, 2017 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. """
  3.  
  4. """
  5.  
  6. def ask_times():
  7.     times = []
  8.     inp = '1'
  9.     while (0<len(inp)):
  10.         print('Введите время: ', end='')
  11.         inp = input()
  12.         if 0<len(inp):
  13.             times.append(inp)
  14.     return times
  15.  
  16. def sec_from_time(stime):
  17.     parts = stime.split(sep=':')
  18.     parts.reverse()
  19.     level = 1
  20.     ret = 0
  21.     for part in parts:
  22.         c = int(part)
  23.         ret += c * level
  24.         level *= 60
  25.     return ret
  26.  
  27. def time_from_sec(sec):
  28.     parts = []    
  29.     parts.append('{:02d}'.format(sec % 60))    
  30.     d = int(sec/60)
  31.     while(d):
  32.         parts.append('{:02d}'.format(d % 60))
  33.         d = int(d/60)
  34.     parts.reverse()
  35.     return ':'.join(parts)
  36.    
  37. times    = ask_times()
  38. sum_sec  = sum(map(sec_from_time, times))
  39. sum_time = time_from_sec(sum_sec)
  40.  
  41. print('Список: ', times)
  42. print('Итого: {0} / {1}'.format(sum_time, sum_sec))
RAW Paste Data
Top