File this under New To Me. The Vim text editor includes a handy command to convert code to HTML.
The command, unsurprisingly, is: :TOhtml
This generates a formatted HTML file which looks like this:
And if I paste this code straight into this post (with minimal editing to make the colours fit a little better with the blog theme), I am reminded the Python style guide recommends a maximum line length of 79 characters.
1 #! /usr/bin/python 2 """ XKComplete: A date reversing completeness counter inspired by XKCD 3 http://xkcd.com/1017/ 4 5 Copyright (C) 2012 Paul Pritchard 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>.""" 19 20 from __future__ import division 21 import datetime 22 import math 23 24 def xkcdate(percentage_complete): 25 """ Returns the percetange completed, either as a date or a year""" 26 today = datetime.date.today() 27 completion = percentage_complete / 100 28 days = float(365.25 * (math.exp(3+20.3444*(completion)**3) - math.exp(3))) 29 try: 30 date = (today - datetime.timedelta(days)).strftime("%A, %d %B %Y") 31 except: 32 dateval = datetime.datetime.today().year - int(days / 365.25) 33 if dateval < 0: 34 dateval = 0 - dateval 35 adbc = " BC" 36 else: 37 adbc = " AD" 38 date = str(dateval) + adbc 39 40 return date 41 42 if __name__ == "__main__": 43 percentage_complete = 0 44 while percentage_complete < 100: 45 percentage_complete = input("Enter percentage complete: ") 46 print xkcdate(percentage_complete)
With thanks to @jk





Talkback