lunes, 7 de noviembre de 2016

My contribution to 99-bottles-of-beer


99-bottles-of-beer.net is site that collects pieces of code in different languages that print the well-known song "99 bottles of beer"


This is my version in Python, using list Comprenhensions





#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
"""
99 Bottles of Beer (by Miguel A. Rico)
List Comprehensions
"""
tn = '%i bottles of beers on the wall, %i bottles of beer\r\nTake one down, pass it around, %i bottle%s of beer on the wall.' + '\r\n--\r\n'
t0 = '1 bottle of beers on the wall, 1 bottle of beer\r\nTake one down, pass it around, no more beer on the wall!' + '\r\n--\r\n'
print reduce((lambda x,y: x + y ), map((lambda x: tn % (x,x,x-1,'s') if x>2 else tn % (x,x,x-1,'') if x>1 else t0),range(99,0,-1)))


0 comentarios:

Publicar un comentario