"""Overview Write a helper function that takes in a Time object and converts it to a more human-readable format. You need only go up to '_ weeks ago'. to_pretty(0) => "just now" http://www.codewars.com/kata/53988ee02c2414dbad000baa/train/python to_pretty(40000) => "11 hours ago" Specifics The output will be an amount of time, t, included in one of the following phrases: "just now", "[t] seconds ago", "[t] minutes ago", "[t] hours ago", "[t] days ago", "[t] weeks ago". You will have to handle the singular cases. That is, when t = 1, the phrasing will be one of "a second ago", "a minute ago", "an hour ago", "a day ago", "a week ago". The amount of time is always rounded down to the nearest integer. For example, if the amount of time is actually 11.73 hours ago, the return value will be "11 hours ago". Only times in the past will be given, with the range "just now" to "52 weeks ago""" def to_pretty(seconds): #your code here minutes = float(seconds/60) hours = float(minutes/60) days = float(hours/24) weeks = float(days/7) if weeks > 1: print "%d weeks ago" % int(weeks) elif weeks == 1: print "1 week ago" % int(weeks) elif days > 1: print "%d days ago" % int(days) elif weeks == 1: print "1 day ago" % int(days) elif hours > 1: print "%d hours ago" % int(hours) elif hour == 1: print "1 hour ago" % int(hours) elif minutes > 1: print "%d minutes ago" % int(minutes) elif hour == 1: print "1 minutes ago" % int(minutes) print minutes to_pretty(1330000000)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question