How to count the total minutes and seconds in Python -


i need count minutes third items of lists list. answer should 10.00 (because it's in minutes). i'm stuck @ error i not defined. code:

def main():     a=[("a","b", 3.10),        ("c","d", 3.20),        ("e","f", 3.30)]     i[2] in a:         c=(i[2]//1)*60         d=(i[2]-(i[2]//1))*100         e=c+d         f=f+e     g=f%60     h=f//60     i=g/100     f=i+h     print(f)  

you need apply 2 fixes make work:

  • use i in place of i[2] on for loop line
  • initialize f before loop:

relevant part of code fixes applied:

f=0 in a:     c=(i[2]//1)*60     d=(i[2]-(i[2]//1))*100     e=c+d     f=f+e  

for summing times in case, can use timedeltas:

from datetime import timedelta import math  a=[("a","b", 3.10),    ("c","d", 3.20),    ("e","f", 3.30)]  s = timedelta() item in a:     seconds, minutes = math.modf(item[2])     s += timedelta(minutes=minutes, seconds=seconds*100)  print s.seconds / 60  # prints 10 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -