89
u/DoomSlayer_C137 Aug 21 '20
But why?
120
u/MeDotPy Aug 21 '20
To flex coding skills by making a code that generates this I guess, if it wasn't auto-generated then probably they just like to suffer
28
Aug 21 '20
Still don't like the final result, I would prefer something like:
def format_duration(seconds):
if not seconds:
return 'now'
times = ((1, 'second'), (60, 'minute'), (3600, 'hour'), (86400, 'day'), (31536000, 'year'))
final = []
for duration, name in reversed(times):
time = seconds // duration
if time:
seconds %= duration
final.append(f'{time} {name}{"s" if time > 0 else ""}')
return ' and '.join(final).replace(' and ', ', ', len(final) - 2)2
10
u/ArkWaltz Aug 21 '20
Wow, learned something new. Had no idea Python had a dedicated floor division operator.
6
u/Gillemonger Aug 21 '20
Theres also the divmod function which does both modulus and integer divison (would've saved you 1 line).
3
u/LeeHide Aug 21 '20
its better to have readable, easy understood code, than "less lines"
5
u/Gillemonger Aug 21 '20
I agree. But to be fair, the divmod function is a built-in function in Python that has existed as far back version 1.4 (1996) so would argue that its use falls into that category.
68
18
u/MisterPyromaniac shameless Aug 21 '20
My God, what is that?
35
u/MeDotPy Aug 21 '20
A program that tells the time with input in seconds as "days, hours, minutes and seconds" without those that are 0. Since it has commas and 'and' you have to put those somehow in the returned string.
Ex: 3727 -> '1 hour, 2 minutes and 7 seconds'
2
u/Jo-C23 Aug 21 '20
What color scheme and font is this?
2
u/MeDotPy Aug 21 '20
The color scheme is the same as it appears in codewars for Python, and the font is Monofonto, I like that one a lot.
135
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20 edited Aug 21 '20
Image Transcription: Code
[There are two sections of code in the post by user karthikbhoshale. The first contains the following code:]
def format_duration(seconds):
if seconds==0:
return "now"
#if seconds ==132375840:
#return '4 years, 68 days, 3 hours and 4 minutes'
minu, sec = divmod(seconds, 60)
hour, minu = divmod(minu, 60)
day,hour=divmod(hour,24)
year,day=divmod(day,365)
if year==0:
if day==0:
if hour==0:
if minu==0:
if sec==1:
return str(sec)+' second'
return str(sec)+' seconds'
if minu==1:
if sec==0:
return str(minu)+' minute'
if sec==1:
return str(minu)+' minute and '+str(sec)+' second'
return str(minu)+' minute and '+str(sec)+' seconds'
if minu>1:
if sec==0:
return str(minu)+' minutes'
if sec==1:
return str(minu)+' minute and '+str(sec)+' second'
return str(minu)+' minute and '+str(sec)+' seconds'
if hour==1:
if minu==0:
if sec==0:
return str(hour)+' hour'
if sec==1:
return str(hour)+' hour and '+str(sec)+' second'
return str(hour)+' hour and '+str(sec)+' seconds'
if minu==1:
if sec==0:
return str(hour)+' hour, '+str(minu)+' minute'
if sec==1:
return str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
return str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
if sec==0:
return str(hour)+' hour, '+str(minu)+' minutes'
if sec==1:
return str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
return str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'
if hour>1:
if minu==0:
if sec==0:
return str(hour)+' hours'
if sec==1:
return str(hour)+' hours and '+str(sec)+' second'
return str(hour)+' hours and '+str(sec)+' seconds'
if minu==1:
if sec==0:
return str(hour)+' hours, '+str(minu)+' minute'
if sec==1:
return str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second'
return str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds'
if sec==0:
return str(hour)+' hours, '+str(minu)+' minutes'
if sec==1:
return str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second'
return str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'
if day==1:
if hour==0:
if minu==0:
if sec==0:
return str(day)+' day'
if sec==1:
return str(day)+' day and '+str(sec)+' second'
return str(day)+' day and '+str(sec)+' seconds'
if minu==1:
if sec==0:
return str(day)+' day and '+str(minu)+' minute'
if sec==1:
return str(day)+' day, '+str(minu)+' minute and '+str(sec)+' second'
return str(day)+' day, '+str(minu)+' minute and '+str(sec)+' seconds'
if minu>1:
if sec==0:
return str(day)+' day and '+str(minu)+' minutes'
if sec==1:
return str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' second'
return str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' seconds'
if hour==1:
if minu==0:
if sec==0:
return str(day)+' day and '+str(hour)+' hour and '+str(sec)
if sec==1:
return str(day)+' day, '+str(hour)+' hour and '+str(sec)+' second'
return str(day)+' day, '+str(hour)+' hour and '+str(sec)+' seconds'
if minu==1:
if sec==0:
return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute'
if sec==1:
return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
if sec==0:
return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes'
if sec==1:
return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'
if hour>1:
if minu==0:
if sec==0:
return str(day)+' day and '+str(hour)+' hours'
if sec==1:
return str(day)+' day, '+str(hour)+' hours and '+str(sec)+' second'
return str(day)+' day, '+str(hour)+' hours and '+str(sec)+' seconds'
if minu==1:
if sec==0:
return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute'
if sec==1:
return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second'
return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds'
if sec==0:
return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes'
if sec==1:
return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second'
return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'
if day>1:
if hour==0:
if minu==0:
if sec==0:
return str(day)+' days'
if sec==1:
return str(day)+' days and '+str(sec)+' second'
return str(day)+' day and '+str(sec)+' seconds'
if minu==1:
if sec==0:
return str(day)+' days and '+str(minu)+' minute'
if sec==1:
return str(day)+' days, '+str(minu)+' minute and '+str(sec)+' second'
return str(day)+' days, '+str(minu)+' minute and '+str(sec)+' seconds'
if minu>1:
if sec==0:
return str(day)+' days and '+str(minu)+' minutes'
if sec==1:
return str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' second'
return str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' seconds'
if hour==1:
if minu==0:
if sec==0:
return str(day)+' days and '+str(hour)+' hour and '+str(sec)
if sec==1:
return str(day)+' days, '+str(hour)+' hour and '+str(sec)+' second'
return str(day)+' days, '+str(hour)+' hour and '+str(sec)+' seconds'
if minu==1:
if sec==0:
return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute'
if sec==1:
return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
if sec==0:
return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes'
if sec==1:
return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'91
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20 edited Aug 22 '20
if hour>1: if minu==0: if sec==0: return str(day)+' days and '+str(hour)+' hours' if sec==1: return str(day)+' days, '+str(hour)+' hours and '+str(sec)+' second' return str(day)+' days, '+str(hour)+' hours and '+str(sec)+' seconds' if minu==1: if sec==0: return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute' if sec==1: return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second' return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes' if sec==1: return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second' return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds' if year==1: if day==0: if hour==0: if minu==0: if sec==0: return str(year)+' year' if sec==1: return str(year)+' year and '+str(sec)+' second' return str(year)+' year and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' year and '+str(minu)+' minute' if sec==1: return str(year)+' year, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' year, '+str(minu)+' minute and '+str(sec)+' seconds' if minu>1: if sec==0: return str(year)+' year and '+str(minu)+' minutes' if sec==1: return str(year)+' year, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' year, '+str(minu)+' minute and '+str(sec)+' seconds' if hour==1: if minu==0: if sec==0: str(year)+' year and '+str(hour)+' hour' if sec==1: return str(year)+' year, '+str(hour)+' hour and '+str(sec)+' second' return str(year)+' year, '+str(hour)+' hour and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' year, '+str(hour)+' hour, '+str(minu)+' minute' if sec==1: return str(year)+' year, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second' return str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' year, '+str(hour)+' hour, '+str(minu)+' minutes' if sec==1: return str(year)+' year, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' year, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds' if hour>1: if minu==0: if sec==0: str(year)+' year and '+str(hour)+' hours' if sec==1: return str(year)+' year, '+str(hour)+' hours and '+str(sec)+' second' return str(year)+' year, '+str(hour)+' hours and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minute' if sec==1: return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minutes' if sec==1: return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds' if day==1: if hour==0: if minu==0: if sec==0: return str(year)+' year and '+str(day)+' day' if sec==1: return str(year)+' year, '+str(day)+' day and '+str(sec)+' second' return str(year)+' year, '+str(day)+' day and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' year, '+str(day)+' day and '+str(minu)+' minute' if sec==1: return str(year)+' year, '+str(day)+' day, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' year, '+str(day)+' day, '+str(minu)+' minute and '+str(sec)+' seconds' if minu>1: if sec==0: return str(year)+' year, '+str(day)+' day and '+str(minu)+' minutes' if sec==1: return str(year)+' year, '+str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' year, '+str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' seconds' if hour==1: if minu==0: if sec==0: return str(year)+' year, '+str(day)+' day and '+str(hour)+' hour and '+str(sec) if sec==1: return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour and '+str(sec)+' second' return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute' if sec==1: return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes' if sec==1: return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds' if hour>1: if minu==0: if sec==0: return str(year)+' year, '+str(day)+' day and '+str(hour)+' hours and '+str(sec) if sec==1: return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours and '+str(sec)+' second' return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute' if sec==1: return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes' if sec==1: return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'85
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20 edited Aug 21 '20
if day>1: if hour==0: if minu==0: if sec==0: return str(year)+' year, and '+str(day)+' days' if sec==1: return str(year)+' year, '+str(day)+' days and '+str(sec)+' second' return str(year)+' year, '+str(day)+' day and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' year, '+str(day)+' days and '+str(minu)+' minute' if sec==1: return str(year)+' year, '+str(day)+' days, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' year, '+str(day)+' days, '+str(minu)+' minute and '+str(sec)+' seconds' if minu>1: if sec==0: return str(year)+' year, '+str(day)+' days and '+str(minu)+' minutes' if sec==1: return str(year)+' year, '+str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' year, '+str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' seconds' if hour==1: if minu==0: if sec==0: return str(year)+' year, '+str(day)+' days and '+str(hour)+' hour and '+str(sec) if sec==1: return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour and '+str(sec)+' second' return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute' if sec==1: return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes' if sec==1: return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds' if hour>1: if minu==0: if sec==0: return str(year)+' year, '+str(day)+' days and '+str(hour)+' hours' if sec==1: return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours and '+str(sec)+' second' return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute' if sec==1: return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes' if sec==1: return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds' if year>1: if day==0: if hour==0: if minu==0: if sec==0: return str(year)+' years' if sec==1: return str(year)+' years and '+str(sec)+' second' return str(year)+' years and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' years and '+str(minu)+' minute' if sec==1: return str(year)+' years, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' years, '+str(minu)+' minute and '+str(sec)+' seconds' if minu>1: if sec==0: return str(year)+' years and '+str(minu)+' minutes' if sec==1: return str(year)+' years, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' years, '+str(minu)+' minute and '+str(sec)+' seconds' if hour==1: if minu==0: if sec==0: str(year)+' years and '+return str(hour)+' hour' if sec==1: return str(year)+' years, '+str(hour)+' hour and '+str(sec)+' second' return str(year)+' years, '+str(hour)+' hour and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' years, '+str(hour)+' hour, '+str(minu)+' minute' if sec==1: return str(year)+' years, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second' return str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' years, '+str(hour)+' hour, '+str(minu)+' minutes' if sec==1: return str(year)+' years, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' years, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds' if hour>1: if minu==0: if sec==0: str(year)+' years and '+return str(hour)+' hours' if sec==1: return str(year)+' years, '+str(hour)+' hours and '+str(sec)+' second' return str(year)+' years, '+str(hour)+' hours and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minute' if sec==1: return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minutes' if sec==1: return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds' if day==1: if hour==0: if minu==0: if sec==0: return str(year)+' years and '+str(day)+' day' if sec==1: return str(year)+' years, '+str(day)+' day and '+str(sec)+' second' return str(year)+' years, '+str(day)+' day and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' years, '+str(day)+' day and '+str(minu)+' minute' if sec==1: return str(year)+' years, '+str(day)+' day, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' years, '+str(day)+' day, '+str(minu)+' minute and '+str(sec)+' seconds' if minu>1: if sec==0: return str(year)+' years, '+str(day)+' day and '+str(minu)+' minutes' if sec==1: return str(year)+' years, '+str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' years, '+str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' seconds'138
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20 edited Aug 21 '20
if hour==1: if minu==0: if sec==0: return str(year)+' years, '+str(day)+' day and '+str(hour)+' hour and '+str(sec) if sec==1: return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour and '+str(sec)+' second' return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute' if sec==1: return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes' if sec==1: return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds' if hour>1: if minu==0: if sec==0: return str(year)+' years, '+str(day)+' day and '+str(hour)+' hours and '+str(sec) if sec==1: return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours and '+str(sec)+' second' return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute' if sec==1: return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes' if sec==1: return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds' if day>1: if hour==0: if minu==0: if sec==0: return str(year)+' years, and '+str(day)+' days' if sec==1: return str(year)+' years, '+str(day)+' days and '+str(sec)+' second' return str(year)+' years, '+str(day)+' day and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' years, '+str(day)+' days and '+str(minu)+' minute' if sec==1: return str(year)+' years, '+str(day)+' days, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' years, '+str(day)+' days, '+str(minu)+' minute and '+str(sec)+' seconds' if minu>1: if sec==0: return str(year)+' years, '+str(day)+' days and '+str(minu)+' minutes' if sec==1: return str(year)+' years, '+str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' years, '+str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' seconds' if hour==1: if minu==0: if sec==0: return str(year)+' years, '+str(day)+' days and '+str(hour)+' hour and '+str(sec) if sec==1: return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour and '+str(sec)+' second' return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute' if sec==1: return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes' if sec==1: return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds' if hour>1: if minu==0: if sec==0: return str(year)+' years, '+str(day)+' days and '+str(hour)+' hours' if sec==1: return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours and '+str(sec)+' second' return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours and '+str(sec)+' seconds' if minu==1: if sec==0: return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute' if sec==1: return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second' return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds' if sec==0: return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes' if sec==1: return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second' return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'[The second section contains the following code:]
def format_duration (seconds): if seconds: times = (1, 60, 3600, 86400, 31536000), ('second', 'minute', 'hour', 'day', 'year') final = [] for i in (4, 3, 2, 1, 0): time = seconds // times [0] [i] if time: seconds %= times [0] [i] final.append (str (time) + ' ' + times [1] [i] + ('s' if time - 1 else '')) return ' and '.join (final).replace (' and ', ', ', len (final) - 2) return 'now'[Beneath the post is a comment]
Nova-Striker: We got out yanderdev
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
94
Aug 21 '20
That's some dedication
96
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20
Haha, thanks. Fortunately, most of it's repeated code I can copy-paste then adjust (if it were all unique I'd have lost the will to live). Still took an hour, but I think it was well spent.
23
u/drdrero Aug 21 '20
and i thought you are a bot
20
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20
I wish; then I wouldn't get tired. Unfortunately, we don't currently have the technology for bots to successfully transcribe. We have one in training but its attempt at this post was totally broken.
7
u/MaddyBeCheesy Aug 21 '20
This is really cool what you did here, is there any way we could get ahold of this code without copying from each comment individually? Many thanks
7
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20
This comment has a link in it, but I think you need a codewars account. Otherwise, I don't know of any other way without going from each comment as you said.
→ More replies (0)6
u/itsTyrion Aug 21 '20
You have 2 misplaced `return`s mid-line and your replace function also replaced `str(year)` with `str(years)`
Yes, I'm going to be THAT guy5
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20
You're not being "that guy", you're being helpful! We want the transcriptions to be as accurate as possible, after all.
I've changed the str(years) back to str(year)'s (can't believe I missed that on my proof-read, but hey, when your eyes are tired...), and I think I've corrected the misplaced returns as well? I noticed quite a few actually, certainly more than 2, that had been indented more than they should've been. If those weren't the ones you meant, please say.
5
u/itsTyrion Aug 21 '20 edited Aug 21 '20
I only noticed after pasting it into VS Code to see if this even works^
Please tell me you didn't look through this monstrosity by hand but used something with error checking? D:
Oh and the indentation looked fine to me, there were to mid line between a plus and
str()call. Example, there were 4Error checked/tested there you go.
2
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 22 '20
Ah, thank you! They should be fixed now. There were actually a few that had slightly too much indentation, but I don't think that would've been picked up by error checking so I, uh, I'm glad I'm a masochist, I suppose?
Yeah, I did look through it by hand. I feel more than a little silly.
5
4
4
3
14
9
6
u/HTTP_404_NotFound bool isEven(int num) => num%2==0 Aug 21 '20
so, to get this straight....
If I want to farm karma here- I just need to create a low-effort script, to just generate a bunch of code which would normally be handled in a much easier to read method, right?
4
u/Dr_Insano_MD Aug 21 '20
Just make a shitload of bad IsEven functions and post it here. I even made a sub for that! /r/badIsEven
2
u/HTTP_404_NotFound bool isEven(int num) => num%2==0 Aug 21 '20
I think I can do even better..... stand-by...
2
u/HTTP_404_NotFound bool isEven(int num) => num%2==0 Aug 21 '20
https://www.reddit.com/r/badcode/comments/idyuiv/extremely_efficient_iseven/
There, am I doing it right? hah.
3
u/Deltaflyer666 Sep 08 '20
I'm not sure... that looks pretty easy to read..... I would do it more like this...
public static bool isEven(int A){Func<int, int, int, int> test = delegate (int X, int Y, int Z) { while ((X < 0 ? 0 - X : X) > (Y / 2)) { X -= (Z < 0 ? -Y : Y); } return X; };return (test(A, 2, A) == 0 ? true : false);}and it works :D
Number Answer---------------------3 False-2 True-1 False0 True1 False2 True3 False
6
5
3
3
3
3
5
2
2
u/NullBrowbeat Aug 21 '20
I also sometimes submit code like this, even though I didn't go that far yet, just to fuck with people. :D
2
2
u/FuzzYetDeadly Aug 22 '20
I remember doing this before learning about the miracle of the % operator and the use of DateTime formatting APIs
2
2
-1
Aug 21 '20
What does this even do? Im not reading through all of it lol
1
u/MeDotPy Aug 22 '20
A program that tells the time with input in seconds as "days, hours, minutes and seconds" without those that are 0. Since it has commas and 'and' you have to put those somehow in the returned string.
Ex: 3727 -> '1 hour, 2 minutes and 7 seconds'
165
u/lerg1 Aug 21 '20
Waiting for image transcription :)