http://99-bottles-of-beer.net/
Was jeder mal programmiert haben sollte
Die Möglichkeiten sind nahezu unbegrenzt.
Hier mal eine Auswahl verschiedenster Möglichkeiten:
Vielleicht sagen einige "geschummelt", aber trotzdem eine Möglichkeit:
Code: Alles auswählen
import re, urllib
print re.sub('</p>', '', re.sub('<br>|<p>|<br/> |<br/>','\n', re.sub('No', '\nNo',
urllib.URLopener().open('http://www.99-bottles-of-beer.net/lyrics.html').read()[3516:16297])))
Code: Alles auswählen
print'\n\n'.join(map(lambda v: '%s bottle%s of beer on the wall, %s bottle%s of beer.\n%s, %s bottle%s of beer on the wall.'%([v,'No'][v==0],['s',''][v==1],[v,'no'][v==0],['s',''][v==1],['Take one down, pass it around','Go to the store and buy some more'][v==0],[v-1,99][v==0] or'No',['s',''][v-1==1]), range(99,-1,-1)))
Code: Alles auswählen
bottle_text = '%s of beer on the wall, %s of beer.'
pass_around_text = 'Take one down and pass it around, %s of beer on the wall.'
bottles = {0: 'no more bottles', 1: '1 bottle'}
for b in range(99, -1, -1):
print bottle_text %(2*(bottles.get(b, str(b)+' bottles'), ))
if b:
print pass_around_text %bottles.get(b-1, str(b-1)+' bottles'), '\n'
print 'Go to the store and buy some more, 99 bottles of beer on the wall.'