Download presentation
Presentation is loading. Please wait.
1
Seconds to (hours,minutes,seconds) conversion
Computers and Programming Chalermsak Chatdokmaiprai Department of Computer Engineering Kasetsart University Revised
8
# 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')
9
# 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')
10
Alternative Solution: Using derived mathematical formalas
(inspired by a student's solution)
12
# 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')
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.