Zum Inhalt springen

99 Bottles of Beer: Unterschied zwischen den Versionen

Enki (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Enki (Diskussion | Beiträge)
update syntax
Zeile 31: Zeile 31:
  }
  }


 
== 99 Bottles in Python ==
  #!/usr/bin/env python
  #!/usr/bin/env python
  # 99 bottles of beer in Python by Ricardo Garcia. Public Domain code.
  # 99 bottles of beer in Python by Ricardo Garcia. Public Domain code.
  # Fully compliant version, pretty indentation, fits in 80x24.
  # Fully compliant version, pretty indentation, fits in 80x24.
   
   
  plural = lambda n: n != 1 and "s" or ""
  plural = lambda n: "s" if n != 1 else ""
  number = lambda n: n == 0 and "No" or str(n)
  number = lambda n: "No" if n == 0 else str(n)
  next = lambda n: (n - 1) % 100
  next = lambda n: (n - 1) % 100
   
   
  pu_line = lambda n: n == 0 and "Go to the store and buy some more" or \
  pu_line = lambda n: "Go to the store and buy some more" or \
"Take one down, pass it around"  
          "Take one down, pass it around" if n == 0
   
   
  verses = lambda n: "%s bottle%s of beer on the wall!\n" \
  verses = lambda n: "%s bottle%s of beer on the wall!\n" \
Zeile 52: Zeile 52:
  number(next(n)), plural(next(n)) )
  number(next(n)), plural(next(n)) )
   
   
  print "\n".join([verses(x) for x in range(99, -1, -1)])
  print "\n".join( verses(x) for x in range(99, -1, -1) )