تبدیل ثانیه به قالب زمانی

تمرین آسان 753 visibility link download flag

برنامه ای بنویسید که تعداد ثانیه ها را از کاربر دریافت کنه و به ساعت و دقیقه و ثانیه تبدیل کند.

- نمونه ورودی :

5648

- نمونه خروجی:

01:34:08

reply 8

visibility

خب من از یک فرمت دهی زمان استفاده کردم.
کار خاصی نیست,صرفا برای زیبایی بود.
ولی میدونم نمیخواستی اما برای این فرمت من مجبور به استفاده از سال,ماه,روز رو داشتم.

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}")
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

ارسال جواب

جوابت را با Markdown بنویس و ثبت کن

×
بستن