Seconds to (hours,minutes,seconds) conversion 01204111 Computers and Programming Chalermsak Chatdokmaiprai Department of Computer Engineering Kasetsart University Revised 2018-01-23
# version 1 sec = int(input('How many seconds? ')) min = sec // 60 sec = sec % 60 hr = min // 60 min = min % 60 print(f'{hr} hours, {min} minutes, {sec} seconds')
# version 2 – same algorithm as version 1 sec = int(input('How many seconds? ')) min,sec = sec // 60, sec % 60 hr,min = min // 60, min % 60 print(f'{hr} hours, {min} minutes, {sec} seconds')
Alternative Solution: Using derived mathematical formalas (inspired by a student's solution)
# version 3 -- using formulas sec = int(input('How many seconds? ')) hr = sec // 3600 min = (sec//60) % 60 sec = sec % 60 print(f'{hr} hours, {min} minutes, {sec} seconds')