Converting seconds into temporal format
Write a program that gets the number of seconds from the user and converts to hours, minutes and seconds.
- Input sample:
5648
- Output sample:
01:34:08
Write a program that gets the number of seconds from the user and converts to hours, minutes and seconds.
- Input sample:
- Output sample:
from datetime import datetime
while True:
try:
Time=int(input(f"Enter the seconds:"))
break
except ValueError:
print(f"Enter the numbers")
#because of calculating the hours
hours=Time//3600
c=Time%3600
#because of calculating the minutes
minutes=c//60
seconds=c%60
#This format needs to get the year,month,day so I added myself
date=datetime(2025,3,8,hours,minutes,seconds)
print(f"The time is {date:%Y/%m/%d :> %H/%M/%S}")
sec = int(input("Enter Second Number: "))
Clock = sec / 3600
Minutes = (sec % 3600) / 60
Seconds = (sec % 3600) % 60
print(int(Clock),":",int(Minutes),":",int(Seconds))
second = 5648
hours = second // 3600
minutes = (second % 3600) // 60
seconds = second % 60
print(f"{str(hours).zfill(2)}:{str(minutes).zfill(2)}:{str(seconds).zfill(2)}")
Submitting answers is currently unavailable.
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.