CodeSolved

Solved Programming Questions & Exercises

Converting seconds into temporal format

Practice Easy 1839/ Download 421 Views

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

8 Answers

def output(data):
    hours=int(data/3600)
    minutes=int(data/60)
    seconds=int(data%60)
    return f"{hours:02}:{minutes:02}:{seconds:02}"
data_user=int(input("enter the seconds>>>>"))
print(output(data_user))
Shina Download Python
seconds = int(input("تعداد ثانیه ها را وارد کنید: "))
hours = seconds // 3600
minutes = (seconds % 3600) // 60
remaining_seconds = seconds % 60
print(f"{hours:02}:{minutes:02}:{remaining_seconds:02}")
Ai Download Python

Well I used a time formatting.
Not a special thing, it was just for beauty.
But I know you didn't want to, but for this format I had to use the year, moon, day.

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}")
seconds=int(input("enter the seconds>>>>"))
hours=seconds/3600
minutes=seconds//3600
sec=seconds%3600
print(hours,":",minutes,":",sec)
Shina Download Python
while True:
    time = int(input("Enter the time in seconds: "))
    if time >= 0:
        second = time % 60
        minute = (time // 60) % 60
        hour = (time // 3600 ) % 24

        print(f'{hour:02}:{minute:02}:{second:02}')
        ask = input("Do you want to try again? (y/n): ")

        if 'n' in ask.lower():
            break
    else:
        print("Invalid input")
        continue
Alireza Download Python
sec = int(input("Enter Second Number: "))
Clock = sec / 3600
Minutes = (sec % 3600) / 60
Seconds = (sec % 3600) % 60

print(int(Clock),":",int(Minutes),":",int(Seconds))
Hadi.x Download Python
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)}")

Emrimo Download Python
zaman = int(input("please enter your zaamn :"))

h = zaman // 3600
sa = zaman % 3600
minut = sa // 60
second = sa % 60

print(f"{h}:{minut}:{second}")
Sumy.amiri Download Python

Submit answer

Submitting answers is currently unavailable.

×
×
Close