Solve python plz help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 3

Solve python plz help

How could i write a program like this Plz share the code Get input as seconds : 24680 Output : 0 days 6 hours 51 minutes 0 seconds

22nd Nov 2021, 3:07 PM
Parham Hidden
Parham Hidden - avatar
5 Answers
+ 2
Hi Parham! You just have to think about how to convert seconds into other parameters and use modulo operator(%) and floor division(//) for the certain places. I made a sample program to help you. a = 90061 h = 60*60 d = 24 d_=a//(h*d) hr=(a//h)%24 m=(a%3600)//60 s=(a%3600)%60 print(d_,"days",hr,"hours",m,"minutes",s,"seconds")
22nd Nov 2021, 3:40 PM
Python Learner
Python Learner - avatar
+ 2
What's wrong You couldn't get the method to solve? OR You don't have sufficient code knowledge?
22nd Nov 2021, 4:33 PM
Prabhas Koya
+ 1
There are probably classes that handle this kind of thing for you in python already. But im not the best at python, so you could manually handle it. I did something similar to this in java a while back. Stole this code online. Should do what you want. seconds = 208920 seconds_in_day = 60 * 60 * 24 seconds_in_hour = 60 * 60 seconds_in_minute = 60 days = seconds // seconds_in_day hours = (seconds - (days * seconds_in_day)) // seconds_in_hour minutes = (seconds - (days * seconds_in_day) - (hours * seconds_in_hour)) // seconds_in_minute print(days, hours, minutes)
22nd Nov 2021, 3:19 PM
CodePunisher
0
Found it Tx guys
22nd Nov 2021, 4:39 PM
Parham Hidden
Parham Hidden - avatar
0
second = int(input('Enter time as seconds : ')) seconds_in_day = 60 * 60 * 24 seconds_in_hour = 60 * 60 seconds_in_minute = 60 seconds_in_seconds = 1 days = int(second / seconds_in_day) hours = (second - (days * seconds_in_day)) // seconds_in_hour minutes = (second - (days * seconds_in_day) - (hours * seconds_in_hour)) // seconds_in_minute seconds =(second - (days * seconds_in_day) - (hours * seconds_in_hour) - (minutes * seconds_in_minute)) // seconds_in_seconds print(second) print(days,'days',hours,'hours',minutes,'minutes',seconds,'seconds')
22nd Nov 2021, 4:39 PM
Parham Hidden
Parham Hidden - avatar