All pastes #26548 Raw Edit

99 bottles of beer!

public python v1 · immutable
#26548 ·published 2005-10-24 22:57 UTC
rendered paste body
#!/usr/bin/python# 99 bottles of beer on the wall.# Inspired by (who'd of thunk) beer!from os import popenfrom time import sleepdef printsay(sometext):  print sometext  voicehandle.write("(SayText \""+sometext+"\")")  # Start talkin' you varmint!  voicehandle.flush()  # It'd be nice if festival would tell us when it's done talking.  sleep(3)# 2 bottles, 1 bottle, no bottlesdef pluralize(somenumber,sometext):  if ( somenumber > 1 ):    retval = str(somenumber)+" "+sometext+"s"  if ( somenumber == 1):    retval = str(somenumber)+" "+sometext  if ( somenumber == 0):    retval = "No "+sometext+"s"  return retval# Open up a pipe to festival so we don't keep respawningvoicehandle = popen("festival","w")# Start with 99 bottlesnum_bottles = 99# Do what now?refrain = "Take one down, pass it around."# As long as there's beer, we drink!while ( num_bottles > 0 ):  printsay(pluralize(num_bottles,"bottle")+" of beer on the wall.")  printsay(pluralize(num_bottles,"bottle")+" of beer.")  printsay(refrain)  num_bottles = num_bottles - 1  printsay(pluralize(num_bottles,"bottle")+" of beer on the wall.")  print "---"