+ 3

date format in python

Given seconds as input, write a program to print in D days H hours M minutes S seconds. Input The input will be a single line containing an integer. Output The output should be a single line containing the D Days H Hours M Minutes S Seconds format. Print only the non-zero values. Explanation For example, if the given seconds are 200. As 200 seconds is equal to 3 minutes and 20 seconds, and days, hours are zero, so ignore the days and hours. So the output should be "3 Minutes 20 Seconds" Sample Input 1 200 Sample Output 1 3 Minutes 20 Seconds Sample Input 2 86400 Sample Output 2 1 Days

5th Jan 2023, 9:02 AM
Mani_ Adepu.
Mani_ Adepu. - avatar
17 odpowiedzi
+ 6
Kenobi , it is not seen as a helpful behavior when we are going to post a ready-made code, as long as the op has not shown his attempt here. it is helpful to give hints and tips, so that the op has a chance to find a solution by himself.
5th Jan 2023, 8:20 PM
Lothar
Lothar - avatar
+ 3
You can use the modulo and the integer division operators. days = input_s // seconds_per_day remaining_s = input_s % seconds_per_day then use the remaining seconds and go on with hours...
5th Jan 2023, 9:12 AM
Lisa
Lisa - avatar
+ 2
Lothar I understand, I was just giving what he was asking for but, yeah it would have been preferable to only give hints
6th Jan 2023, 6:11 AM
Kenobi
Kenobi - avatar
+ 2
for this you should use the integer division operator (//) and the modulo division operator (%) and I'll make this a separate function. We will start off by making the function and making it accept one argument and that's is the seconds that we want to format. After that you make a value that would be the response that we will return at the end of the function. Then we start off by getting the days by dividing the seconds that we passed into the function by 86400 and only getting the integer part by using the integer operator "//" and then set the passed argument to the remaining of the division by using the modulo operator then use an if statement to check if the days value that we got isn't equal to neither 0 or 1 and if it's true we set the result value that we created at the start to the days value followed by "days" and make an elif statement to check if the days are equal to 1 and if it's true we set the result as we did last time but now we will add "day" then do the same thing to the others
6th Jan 2023, 7:01 PM
SwirX
SwirX - avatar
7th Jan 2023, 7:57 AM
Smith Welder
Smith Welder - avatar
+ 2
here's the code if the explanation wasn't clear https://code.sololearn.com/cVAjsGOzSe0o/?ref=app
7th Jan 2023, 1:50 PM
SwirX
SwirX - avatar
+ 2
print ("hello""nasa""bmw".upper()) dont working... the upcoming code takes text data as input. write the code to convert it to upper case and display in on the screen 'hello' 'nasa' 'bmw' can you help me this dont working what problem ?
7th Oct 2023, 6:46 AM
AMIR H R 👑💎🕹📱📡 💪
AMIR  H  R 👑💎🕹📱📡 💪 - avatar
+ 2
I type the code above but it didn't work print("hello""nasa""bmw".upper())
9th Oct 2023, 6:53 AM
AMIR H R 👑💎🕹📱📡 💪
AMIR  H  R 👑💎🕹📱📡 💪 - avatar
+ 1
This is a task description. What is your question?
5th Jan 2023, 9:05 AM
Lisa
Lisa - avatar
+ 1
You need a code to execute this Task?
5th Jan 2023, 9:06 AM
Kenobi
Kenobi - avatar
+ 1
matthias boettcher yeah I tried it but there were a few errors, I modified it so it works now https://code.sololearn.com/c9JABhks30mT/?ref=app
7th Jan 2023, 8:23 AM
Kenobi
Kenobi - avatar
+ 1
matthias boettcher you're right, I fixed it
7th Jan 2023, 8:39 AM
Kenobi
Kenobi - avatar
0
Yes
5th Jan 2023, 9:07 AM
Mani_ Adepu.
Mani_ Adepu. - avatar
0
input = int(input) second = input % 60 minutes = second // 60 hours = minutes // 60 day = hours // 24 if day != 0: print(day+"Day") if hours != 0: print(hours+"Hours") if minutes != 0: print(minutes + " Minutes") if seconds != 0: print(seconds + "Seconds") There is surely à better way but that should works
5th Jan 2023, 9:15 AM
Kenobi
Kenobi - avatar
0
Kenobi, i like the idea of your code but im afraid that wont work. Firstly, its gotta be: Minutes = input // 60 But then still i dont think itll work with really high numbers. Im not really sure and will try to think about it more deeply, but for starters ill just disagree 😋 Edit: First idea: Youll have to substract the hours from the days, the minutes from the hours etc. or youll get smth like 2days 49hrs 78mins no? Wouldnt it be better to start with the days and go backwards? Edit2: https://code.sololearn.com/c022Nh8JO2MU/?ref=app
7th Jan 2023, 12:20 AM
matthias boettcher
0
Kenobi, I think you still have to have to substract the hours that are included in the days. Try input 86400 (1Day)
7th Jan 2023, 8:37 AM
matthias boettcher
- 1
I need the Suitable Code For This.
5th Jan 2023, 9:07 AM
Mani_ Adepu.
Mani_ Adepu. - avatar